JDK-8219962 : java -version cannot find libjava when java in bin/bin directory
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 9,11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2019-02-28
  • Updated: 2024-09-10
  • Resolved: 2024-09-10
Related Reports
Duplicate :  
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
$ cat /etc/redhat-release
CentOS release 6.10 (Final)
$ uname -a
Linux pnode-01.csrs 2.6.32-754.11.1.el6.x86_64 #1 SMP Tue Feb 26 15:38:56 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ ./java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)


A DESCRIPTION OF THE PROBLEM :
If the path provided to the --output option ends with a directory called "bin", the resulting image is not runnable, because Java does not find the necessary dynamic libraries.
In particular, executing java results in the following error:
Error: could not find libjava.so
Error: Could not find Java SE Runtime Environment.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1 - Download jdk-11.0.2, unpack it into a directory $JDK_HOME
2 - create a modular HelloWorld application, call the module HelloModule
3 - compile the application, put the class files in a directory $CLASSES
4 - execute $JDK_HOME/bin/jlink --module-path $CLASSES:$JMOD --add-modules HelloModule --output bin
5 - execute ./bin/bin/java -version
6 - repeat step 4 using --output dist/bin
7 - repeat step 5

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The java executable should be able to find the dynamic libraries without assuming that the full path of the java executable contains only one instance of "bin"
ACTUAL -
The java executable can't find the dynamic libraries if the --output path  provided to jlink ends with "bin"

CUSTOMER SUBMITTED WORKAROUND :
Don't use a --output path that ends with "bin"

FREQUENCY : always



Comments
This was fixed in https://bugs.openjdk.org/browse/JDK-8268974 and I can no longer reproduce this issue after that fix (without that fix, I can reproduce the issue).
10-09-2024

This is a long standing issue with the java launcher where it gets confused by bin/bin.
01-03-2019

This issue is reproducible in only Linux and not in Windows. Behavior is same in Oracle and OpenJDK, Ubuntu 18.0.4 LTS using OpenJDK 11.0.2/13-ea+10 : ------------------------- $javac -d out src/module-info.java $javac -d out --module-path out src/com/logicbig/example/Test.java $ jlink --module-path ~/JDK/openJDK-11.0.2/jdk-11.0.2/jmods:out --add-modules test.example --output bin $ /home/dcsuser/TestCases/install/jlink-example/bin/bin/java -version Error: could not find libjava.so Error: Could not find Java SE Runtime Environment. When used 'build' instead of 'bin' for --output path, there was no error and it showed the correct java version.
01-03-2019