Comment 0 for bug 1556997

Revision history for this message
Václav Šmilauer (eudoxos) wrote : JAVA_HOME auto-detection fails due to whitespace in update-java-alternatives output

Running imagej fails with the following message:

   Open other images in this ImageJ panel as follows:
     imagej -p 3 <image1> [<image2> ... <imageN>]

   No JVM found to run ImageJ
   Please apt-get install a JVM to run ImageJ or
   set JAVA_HOME if it's not a JVM from a Debian Package.

even though multiple JVM's are installed here.

The problem is that the /usr/bin/imagej script detects JAVA_HOME using

   JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | cut -d' ' -f 3)

which is empty as the output of update-java-alternatives -l is (note multiple spaces between columns):

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64

and cut -d' ' -f3 selects space. The solution is to squeeze multiple spaces before running cut, so the line should read:

   JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | tr -s ' ' | cut -d' ' -f 3)

which then gives the correct output (/usr/lib/jvm/java-1.8.0-openjdk-amd64 in my case) and makes imagej run as expected.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: imagej 1.50d+dfsg-1
ProcVersionSignature: Ubuntu 3.19.0-49.55-lowlatency 3.19.8-ckt12
Uname: Linux 3.19.0-49-lowlatency x86_64
NonfreeKernelModules: btrfs ufs qnx4 hfsplus hfs minix ntfs msdos jfs xfs libcrc32c pci_stub binfmt_misc cfg80211 joydev hid_logitech_hidpp snd_hda_codec_hdmi snd_hda_intel snd_hda_controller eeepc_wmi asus_wmi sparse_keymap snd_hda_codec x86_pkg_temp_thermal intel_powerclamp video snd_hwdep snd_pcm snd_seq_midi kvm_intel snd_seq_midi_event kvm snd_rawmidi crct10dif_pclmul snd_seq crc32_pclmul snd_seq_device snd_timer snd aesni_intel sb_edac aes_x86_64 lrw soundcore gf128mul glue_helper edac_core ablk_helper serio_raw mei_me cryptd mei lpc_ich tpm_infineon 8250_fintek shpchp mac_hid nct6775 hwmon_vid coretemp parport_pc ppdev nfsd lp auth_rpcgss nfs_acl lockd grace sunrpc parport autofs4 raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq raid0 multipath linear hid_logitech_dj usbhid hid raid1 amdkfd amd_iommu_v2 mxm_wmi radeon igb ttm drm_kms_helper dca psmouse ptp drm ahci pps_core libahci i2c_algo_bit wmi
ApportVersion: 2.20-0ubuntu3
Architecture: amd64
CurrentDesktop: XFCE
Date: Mon Mar 14 15:56:23 2016
PackageArchitecture: all
SourcePackage: imagej
UpgradeStatus: Upgraded to xenial on 2012-03-12 (1463 days ago)