2

I searched a lot in So. But could not find a proper solution. Here is the problem

I have some .so files to load in my java application.

I created a Java class with main method and loading it using System.load();

System.load("/home/myfolder/TFS-SDK-11.0.0/redist/native/linux/x86_64/libnative_auth.so");        
System.load("/home/myfolder/TFS-SDK-11.0.0/redist/native/linux/x86_64/libnative_console.so");     

And then my Java codes. When I run the class as Java application, it is working fine.

Then I added the same code in my Java web application. And I run it in tomcat. But It is showing some error

Exception in thread "main" java.lang.UnsatisfiedLinkError

I found that this is because it is not loading the library files.

When I searched in google, I found some solutions but it didnt help me. I tried adding the so file location in

setenv.sh, catalina.sh in JAVA_OPTS. But none worked.

Some solutions I don't even understood.

Can someone give the step by step proces of

Where to put the so files in tomcat? Which file I should edit and What should I add?

I searched a lot. But most answers I don't understand.

Cœur
  • 37,241
  • 25
  • 195
  • 267
iCode
  • 8,892
  • 21
  • 57
  • 91
  • 1
    possible duplicate of [how to make a jar file that include dll files](http://stackoverflow.com/questions/1611357/how-to-make-a-jar-file-that-include-dll-files) – chrylis -cautiouslyoptimistic- Nov 23 '13 at 07:33
  • @chrylis I dont want to make a Jar and all. I want to put those SO file in side tomcat(if necessary) and load the files. Or in some config files in tomcat I should be able to mention the location of SO files(I don't know which config file). – iCode Nov 23 '13 at 07:43

1 Answers1

0

When you run your app in a web container such as Tomcat, your main method will NOT be called.

If you want to load these libraries when the container starts, then I'd suggest using a ContextListener.

Try googleing "context listener example in java" - you'll get plenty of hits and plenty of examples to follow.

You will probably also need to add these libraries on to your Unix Library Path. It's usually convenient to do this in your tomcat start up script. The name of the library path variable is unix flavour dependent, so I can't tell you what that path is I'm afraid.

DaveH
  • 7,187
  • 5
  • 32
  • 53
  • Startup script you meant `startup.sh`? I am using Ubuntu – iCode Nov 25 '13 at 04:25
  • yes - startup.sh ( or possibly catalina.sh ). It's the start up script for tomcat, not the start up script for the whole unix installation – DaveH Nov 25 '13 at 11:42