I am working on an java component which need some libraries i.e .dll for windows system and .so files for Linux system. So I prepared an java application in netbeans and added some dependency jars and build the project.
Execution on Windows:
When I tried to run jar file on Windows system using command java -jar appName.jar I got java.lang.UnsatisfiedLinkError so I specified java.library.path while execution like java -Djava.library.path=full\\path\\to\\libs -jar appName.jar and it got run successfully on Windows.
Execution on Linux(ubuntu) :
When I tried to execute same jar file on ubuntu with the same command java -Djava.library.path=/path/to/libs -jar appName.jar I got error saying some .so file are not found on specified location (I checked file location and permissions, all is ok)
Updated (added error):
ubuntu#ubuntu-HP-dx2480-MT-KL969AV:~/Desktop$ java
-Djava.library.path=/home/ubuntu/Desktop/bin -jar JavaApplication4.jar
initialize on Thread[AWT-EventQueue-0,6,main] with library path bin
bin/jcef_helper: error while loading shared libraries: libcef.so:
cannot open shared object file: No such file or directory
contains of bin folder
-rwxr-xr-x 1 ubuntu ubuntu 1483321 Jun 18 2014 cef.pak
-rwxr-xr-x 1 ubuntu ubuntu 3258231 Jun 18 2014 devtools_resources.pak
-rwxr-xr-x 1 ubuntu ubuntu 971264 Jun 11 2014 ffmpegsumo.dll
-rwxr-xr-x 1 ubuntu ubuntu 9994752 Jun 11 2014 icudt.dll
-rwxr-xr-x 1 ubuntu ubuntu 429568 Jun 18 2014 jcef.dll
-rwxr-xr-x 1 ubuntu ubuntu 481488 Jun 18 2014 jcef_helper
-rwxr-xr-x 1 ubuntu ubuntu 233984 Jun 18 2014 jcef_helper.exe
-rwxr-xr-x 1 ubuntu ubuntu 53280768 Jun 11 2014 libcef.dll
-rwxr-xr-x 1 ubuntu ubuntu 105317136 Jun 18 2014 libcef.so
-rwxr-xr-x 1 ubuntu ubuntu 1309288 Jun 18 2014 libffmpegsumo.so
-rwxr-xr-x 1 ubuntu ubuntu 1047296 Jun 18 2014 libjcef.so drwxrwxrwx 2 ubuntu ubuntu 4096 Dec 23 11:29 locales
By some searching I come to know that I have try with LD_LIBRARY_PATH environment variable so I created an sh file having command:
export LD_LIBRARY_PATH=/path/to/libs
java -jar /path/to/appName.jar
and when I run sh file my program runs successfully.
So my question is why java.library.path is not works for ubuntu (linux)? Is it like java.library.path is only for windows?
So my question is why java.library.path is not works for ubuntu (linux)? Is it like java.library.path is only for windows?
It does work, we use it a lot. Start your application with -XshowSettings:properties and take a look at the search path for debugging.
We usually deploy the libraries as a package to /usr/local/lib, since the libraries are often used by other components too. Don't forget to call ldconfig after placing a new library in there (so much for the export LD_LIBRARY_PATH part).
As far as i remember it should be enough with just adding the folder with -Djava.library.path if i recall correctly. I will look into it and tell you later to clarify.
Also please post readlink -f /home/ubuntu/Desktop/bin, file /home/ubuntu/Desktop/bin/libcef.so and ldd /home/ubuntu/Desktop/bin/libcef.so.
Update:
I will try to explain why things work and why not.
Lets talk about java.library.path. This property is used by the VM for looking up libraries. Take a look at java.lang.System#load*(String libName) for reference. The java.library.path property has some paths pre-set, the following shows the output on my ubuntu box:
ortang#vbox-devel:~$ java -XshowSettings:properties
Property settings:
...
java.library.path = /usr/java/packages/lib/amd64
/usr/lib/x86_64-linux-gnu/jni
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
/usr/lib/jni
/lib
/usr/lib
Be aware that using this property will overwrite the existing property.
ortwin#vbox-devel:~$ java -Djava.library.path=/some/other/folder:/yet/another/one -XshowSettings:properties
Property settings:
...
java.library.path = /some/other/folder
/yet/another/one
So far so good. The JVM is looking only in the folders defined in that property!
The libraries you make the JVM to load will most likely have dependencies to other libraries. Be aware that these dependencies are looked up by the operating system, just as any other shared library!
So to solve your problem you have to make sure that the libraries you load have their dependencies resolved! Use ldd for debugging that matter.
The LD_LIBRARY_PATH environment variable does a similar job, as it adds paths that will be used for library lookup by the OS. I am no fan of using it in production environments.
My best guess for your problem is that you have to use both java.library.path and LD_LIBRARY_PATH. Indeed, j.l.p is for java to load you JNI library while L_L_P is for the operating system to load the shared library and any dependent libraries. If your shared library depends on other libraries in other paths you have to list those paths.
it's seem that jcef did not find it's depenencies, try ldd libcef.so |grep "not found" and ldd libjcef.so |grep "not found" and fix the missing libraries. On my machine (ubuntu 14.04) It miss libudev.so.0 , my machine has /lib/x86_64-linux-gnu/libudev.so.1 so trick it by ln -s /lib/x86_64-linux-gnu/libudev.so.1 /lib/x86_64-linux-gnu/libudev.so.0 and sudo ldconfig to reload ld cache.
I meet the same problem, I use "-Djava.library.path", but it does't work.
I add "-Dsun.boot.library.path" as a try, it works!
try:
java -Dsun.boot.library.path=/path/to/libs -jar appName.jar
Related
I'm using RHEL8 which has default OpenJDK installed.
which java command points to /usr/bin/java.
java -version gives openjdk version "1.8.0_252"
Installed java in /u01/app/java/ location. Modified the .bashrc like below & sourced it.
export JAVA_HOME=/u01/app/java/jdk1.8.0_241/
PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
Now JAVA_HOME points to /u01/app/java/jdk1.8.0_241/ But which java or java -version still points to the OpenJDK.
Added the same in .bash_profile file & removed it from the .bashrc : Results are same
Deleted OpenJDK & made changes in .bash_profile. But by doing so ended up with "Command not found" error.
How can i fix it?
It was Path issue.
I have given PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH" for PATH. which should not be the case.
Modified my PATH to below. It worked.
PATH="$JAVA_HOME/bin:$HOME/.local/bin:$HOME/bin:$PATH"
export PATH
That happens because when you invoke java it is actually invoked /usr/bin/java, which, issuing ls -l /usr/bin/java you will probably see is linked to the openjdk installation (probably through a double link: the first one being /usr/bin/java to /etc/alternatives/java and the second one being the link to the "real" java executable). For example, on my debian:
gianluca#asus-debian:~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 mag 20 2018 /usr/bin/java -> /etc/alternatives/java
gianluca#asus-debian:~$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 nov 22 2019 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
You can fix in two ways:
Dirty way, you manually update all the symbolic links in /usr/bin that lead to the unwanted java version and make them point to the desired one
Clean way, you use alternatives that does the job for you.
You can read more about alternatives for RHEL here (mid-page... "The longer version").
Good link
On Windows I noticed that the java binary is in two different locations (I have the JDK installed):
C:\Program Files\Java\jdk1.8.0_121\bin\java.exe
C:\Program Files\Java\jdk1.8.0_121\jre\bin\java.exe
Similarly on a Unix box that I have access to, there are two copies, one in jre/bin and one just in bin. I am not sure if this other one is the JDK or just a JRE installation.
In both cases, they are the same size as each other. I confirmed they aren't symlinked on the Linux side although I suppose they could be hard linked.
The contents of jdk/bin/ is the Java binaries that are included with the Java Developers Kit. The Java binaries inside of jdk/jre/bin are the Java Runtime Environment's binaries.
If you have the JDK version of Java then use the one in jdk/bin/.
But they are the same
If you look at the executables there is actually no difference in them, so it really doesn't matter.
$ pwd
/usr/java/jdk1.7.0_45
$ ll jre/bin/java
-rwxr-xr-x. 1 root root 7718 Oct 8 2013 jre/bin/java
[saml#greeneggs jdk1.7.0_45]$ ls -l bin/java
-rwxr-xr-x. 1 root root 7718 Oct 8 2013 bin/java
$ cmp jre/bin/java bin/java
$
I'm attempting to compile my companies codebase using Maven which is wrapped in an Ant launcher for backwards compatibility reasons. I am running Oracle Linux 6.6, Java 1.7 u79-b14, Ant 1.7.1 and Maven 3.0.5 which are versions dictated to me by the enterprise infrastructure team.
When I set JAVA_HOME I get the following error when executing Ant Error: Could not find or load main class org.apache.tools.ant.launch.Launcher but if JAVA_HOME is commented out then Ant seems to run just fine.
#~/.bashrc
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export MAVEN_HOME=/usr/share/maven
export M2_HOME=/usr/share/maven
export MAVEN_OPTS="-Xmx1024m"
export BUILD_CHROOT="/home/builduser/builds"
Included to help is the location at which Java is installed.
[builduser#iaas-a-jen03 ~]$ which java
/usr/bin/java
[builduser#iaas-a-jen03 ~]$ ls -la /usr/bin/java
lrwxrwxrwx 1 root root 22 Jun 30 11:58 /usr/bin/java -> /etc/alternatives/java
[builduser#iaas-a-jen03 ~]$ ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 46 Jun 30 11:58 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
The issue was resolved by following the steps found in this blog post... http://pkolomeitsev.blogspot.co.uk/2015/01/apache-ant-error-could-not-find-or-load.html
ant --execdebug was the key to creating the right folders. Then I just had to make sure that java-1.7.0-openjdk-devel.x86_46 was installed and voila!
I want to start my tomcat with a different java version than the "standard one". On my server java 6 is installed (java -version returns: java version "1.6.0_34")
I also downloaded a java 7 jdk and put it to /opt/oracle/7/jdk1.7.0_55/ and wanted my tomcat to run with java 7. So I added export JAVA_HOME=/opt/oracle/7/jdk1.7.0_55 to my script /etc/init.d/tomcat7.
When I try to start my tomcat via sudo /etc/init.d/tomcat7 start I get /opt/tomcat7/bin/catalina.sh: 1: eval: /opt/oracle/7/jdk1.7.0_55/bin/java: not found
But when I type ll /opt/oracle/7/jdk1.7.0_55/bin I get -rwxr-xr-x 1 root root java* So the path should be correct!?
I can't figure out why it doesn't work. Any hints appreciated. :-)
EDIT:
I probably just downloaded the wrong jdk (32 bit instead of 64)
You probably downloaded the wrong JDK. From your comments, it seems to be a 32bit JDK. If you have a 64bit Linux, then you can't load the executables.
uname -m tells you the architecture of your system. It should be i686 or i586 but probably is x86_64.
I'm running into this error when I'm building android 2.3 from source code on Ubuntu 10.04. I am suspecting it is an issue with a path or something along those lines but cannot figure it out. I have seen similar people have this issue but I haven't found any solution that works for me. I included some information about my environment, any help would be appreciated(if you know my path's are correct then even that would be beneficial as I could start look into other possible sources of error). Thanks.
java -version should indicate the installation was successful:
juan#juan-desktop:~/bin/WORKING_DIRECTORY$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
My .bashrc has:
export JAVA_HOME=/usr/java/jdk1.6.0_45/bin/java
PATH=$PATH:/usr/local/bin:/usr/bin:/usr/lib:/usr/lib/jvm:/usr/lib/jvm/jdk1.6.0_45/bin
Some more info:
juan#juan-desktop:~$ namei -mx /usr/bin/java
f: /usr/bin/java
Drwxr-xr-x /
drwxr-xr-x usr
drwxr-xr-x bin
lrwxrwxrwx java -> /etc/alternatives/java
Drwxr-xr-x /
drwxr-xr-x etc
drwxr-xr-x alternatives
lrwxrwxrwx java -> /usr/lib/jvm/jdk1.6.0_45/bin/java
Drwxr-xr-x /
drwxr-xr-x usr
drwxr-xr-x lib
drwxr-xr-x jvm
drwxr-xr-x jdk1.6.0_45
drwxr-xr-x bin
-rwxr-xr-x java
I'm posting my solution on here in case anyone else runs into a similar problem and stumbles across this. I simply re-installed my OS, ran the steps again, and everything worked perfectly fine this time. I must have caused some sort of error on my machine as I ran the same exact steps too. Here is what I did to manually install Java 6 on a clean machine:
Install Java 6(.bin format) from the Oracle website
Give it executable permissons and execute it
Add a jvm folder to usr/lib/
Move your Java 6 folder to usr/lib/jvm
Link java/javaws/javac to usr/bin using the ln -s command
Add your Java6 and Java/bin location to your path. For me its:
export JAVA_HOME=usr/lib/jvm/jdk1.6.0_45
export PATH=/usr/bin:$JAVA_HOME/bin