1

I have compiled a modular Java application using OpenJDK 11.0.2 on Windows 10. I have downloaded the linux OpenJDK 11.0.2 jmods and I have used them to create a run-time image using jlink. I have copied the image to a CentOS 6.10 VM, and if I try to launch java (the one in the bin folder in of the image generated by jlink), it fails saying "Error: could not find libjava.so". The libjava.so file is in the lib folder of the run-time image. If I move the java executable to /usr/bin and the libjava.so to /usr/lib, it complains about not finding a different .so file, so I guess this means that it expects to find the contents of the lib folder in the /usr/lib directory. On Windows there is no such problem (i.e. if I create an image using the Windows jmod files). I'm reluctant to solve this problem by creating an installation script that creates tenths of symlinks, but I can't think of any other solution. I have also tried to define a $JAVA_HOME variable that points to the [run-time image]/bin folder, but it still doesn't work.

  • 1
    Did you check the file permissions after you copied to the CentOS machine? – Alan Bateman Feb 26 '19 at 08:04
  • Yes, the permissions are rwx for the user that executes Java: – Vittorio Torroni Feb 28 '19 at 07:55
  • I have submitted a bug (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8219703) and the feedback from Oracle is "Self-contained application packages must be built on the operating system on which it is intended to run." – Vittorio Torroni Feb 28 '19 at 08:15
  • Ok, I have found the root cause of the problem. On the CentOS machine, if I execute jlink as root, it creates a working image (i.e., java starts, even if launched by a non-root user), but if I execute it as a regular user, it creates a non-working image (i.e. java complains that it can't find libjava.so, even if I chmod -R 777 the entire folder containing the custom run-time image). So I went back the Windows, started the cmd prompt as administrator, run the jlink again, copied the image to CentOS, and sure enough it works. – Vittorio Torroni Feb 28 '19 at 14:10
  • I did some more tests, and being root had nothing to do with it. The real problem was that I was using an output path (i.e. a value for the --output option) which ended with a directory called "bin" and this apparently causes Java to not find the dynamic libraries it needs, perhaps because it tries to locate them relative to the bin folder generated by jlink. – Vittorio Torroni Feb 28 '19 at 16:27

1 Answers1

0

I did some more tests and I have found the reason for this misbehaviour. The real problem was that I was using an output path (i.e. a value for the --output option) which ended with a directory called "bin" and this apparently causes Java to not find the dynamic libraries it needs, perhaps because it tries to locate them relative to the bin folder generated by jlink. So, for example "--output bin" or "--output dist/bin" don't work, while for example "--output dist" or "--output bin/dist" work.