Report this

What is the reason for this report?

Error loading a Java native library (.so) in Apache Tomcat 7 in a CentOS7 DigitalOcean server

Posted on November 6, 2017

I am new to DigitalOcean, Linux and libraries, and deeply appreciate any help from you on the following issue: I have been trying to make a native library work (libjsmile.so) in a web application with Apache Tomcat 7 on a Linux CentOS 7 DigitalOcean server, but I still haven’t succeeded. I was able to use this wrapper library (libjsmile.jnilib) as a Java application or a web application with Apache Tomcat 7 on a Mac. And I was able to load libjsmile.so as a Java application on this CentOS 7 server. The error starts to occur when I want to load libjsmile.so in a web application with Apache Tomcat 7 in this CentOS 7 server. I have tried to add LD_LIBRARY_PATH=“/usr/share/java/tomcat” and/or JAVA_OPTS=“-Djava.library.path=/usr/share/java/tomcat” to the Tomcat configuration file (tomcat.conf) and put the libjsmile.so inside that path. I have also tried to use System.loadLibrary(“jsmile”); or System.load(“/usr/share/java/tomcat/libjsmile.so”); Although some of the above methods could work in a Java application on the CentOS7 server, none of them work when I change to a web application using apache tomcat 7 on the CentOS7 server. It either gives the following error: java.lang.UnsatisfiedLinkError: smile.Wrapper.nativeStaticInit() Or just hang there (keep waiting for a response). Thanks a lot for any of your suggestions!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

This error java.lang.UnsatisfiedLinkError: smile.Wrapper.nativeStaticInit() indicates that the JVM cannot find the native library or one of its dependencies.

Here’s a couple of steps you could take to try and fix the issue:

1. Verify the .so file

Make sure that the libjsmile.so file is compatible with your Linux system. If it was compiled on a different architecture, or if it’s a 32-bit library and you’re using a 64-bit JVM (or vice versa), it won’t work.

You can use the file command to check the architecture of your .so file:

file /usr/share/java/tomcat/libjsmile.so

2. Check Dependencies

Make sure that all dependencies of libjsmile.so are met. You can check this with the ldd command:

ldd /usr/share/java/tomcat/libjsmile.so

This will list all shared libraries that your .so file depends on. If there are any ‘not found’ entries, you’ll need to install those libraries.

3. Update LD_LIBRARY_PATH

Update the LD_LIBRARY_PATH environment variable to include the directory where libjsmile.so is located. This is not usually recommended for system services, but you could give it a try for debugging purposes. Update the setenv.sh script in your Apache Tomcat’s bin directory:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/share/java/tomcat

Then restart Apache Tomcat and see if the issue is resolved.

4. Set java.library.path

The java.library.path should be set to the directory containing the shared library. Add the following line to the setenv.sh script in your Apache Tomcat’s bin directory:

export CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=/usr/share/java/tomcat"

Then restart Apache Tomcat and see if the issue is resolved.

Remember, when editing configuration files or scripts, it’s a good practice to back up the original file.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.