Discussion:
Using native and ld_library_path
Andreas Andersson
2005-01-26 15:00:47 UTC
Permalink
Hi!

My application needs to use a native share library. When running normal
java program from the commandline it works if I just set LD_LIBRARY_PATH
to point to the .so-file. But since tomcat runs as suid (I guess thats
why) LD_LIBRARY_PATH is ignored. What can I do instead? Is there any way
I can set this parameter in tomcat?

I've turned of security to see if that could be the error but it wasn't.

Any help is welcome :)
--
Andreas Andersson
IT Dept.
Travelstart Nordic
***@travelstart.se
http://www.travelstart.se
Ben Souther
2005-01-26 15:06:39 UTC
Permalink
Have you tried setting LD_LIBRARY_PATH as a java option at Tomcat
startup time?
Post by Andreas Andersson
Hi!
My application needs to use a native share library. When running normal
java program from the commandline it works if I just set LD_LIBRARY_PATH
to point to the .so-file. But since tomcat runs as suid (I guess thats
why) LD_LIBRARY_PATH is ignored. What can I do instead? Is there any way
I can set this parameter in tomcat?
I've turned of security to see if that could be the error but it wasn't.
Any help is welcome :)
Andreas Andersson
2005-01-26 15:16:32 UTC
Permalink
Post by Ben Souther
Have you tried setting LD_LIBRARY_PATH as a java option at Tomcat
startup time?
I have tried to export the value (export
LD_LIBRARY_PATH=/path/to/so-file) in both catalina.sh and
/etc/init.d/tomcat4. Is there any other way to do it?

Could I do something like
java -DLD_LIBRARY_PATH=/path/to/so-file ?
--
Andreas Andersson
IT Dept.
Travelstart Nordic
***@travelstart.se
http://www.travelstart.se
Caldarale, Charles R
2005-01-26 15:47:51 UTC
Permalink
Subject: Re: Using native and ld_library_path
Could I do something like
java -DLD_LIBRARY_PATH=/path/to/so-file ?
Yes, except the property name is java.library.path (LD_LIBRARY_PATH is only the environment variable name). The default for Linux systems is /usr/lib:/lib (for UNIX, it's just /usr/lib), so you could put the .so file there.

I think you have to be careful about where the System.loadLibrary() call is issued, since a native library can only be loaded for one class loader. This has implications for sharing the code across applications and for redeploying applications.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Andreas Andersson
2005-01-27 07:52:27 UTC
Permalink
Post by Caldarale, Charles R
Yes, except the property name is java.library.path (LD_LIBRARY_PATH is only the environment variable name). The default for Linux systems is /usr/lib:/lib (for UNIX, it's just /usr/lib), so you could put the .so file there.
I tried putting all of the files there but still get the same
java.lang.UnsatisfiedLinkError when trying to invoke the method. When
issuing the command
System.out.println(System.getProperties().get("java.library.path"));
right before the error occurs I can see the correct folders there. Is
there anything else that would differ between running this through
tomcat than from prompt?
Post by Caldarale, Charles R
I think you have to be careful about where the System.loadLibrary() call is issued, since a native library can only be loaded for one class loader. This has implications for sharing the code across applications and for redeploying applications.
I never use System.loadLibrary() in the javacode that does work (outside
tomcat), do I have to?
--
Andreas Andersson
IT Dept.
Travelstart Nordic
***@travelstart.se
http://www.travelstart.se
Caldarale, Charles R
2005-01-27 13:27:51 UTC
Permalink
Subject: Re: Using native and ld_library_path
I never use System.loadLibrary() in the javacode that does
work (outside tomcat), do I have to?
Take a look at:
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step1.html

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Andreas Andersson
2005-02-01 19:12:56 UTC
Permalink
Post by Caldarale, Charles R
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step1.html
Hi again. I did take a look but nothing helped me there and I still need
help.

My guess is that tomcat has some restrictions when it comes to loading
native code.

I have several native libraries. One of them is loaded and executed from
my code, the rest is used by the first one.

What confuses me is that this works on my tomcat on windows but not
linux. It also works on a standalone program on that same linux machine.
But not my tomcat on linux.

I've tried putting the libraries in /usr/lib. That works for my
standalone but not tomcat.

I've tried setting -Djava.library.path in catalina.sh, that doesn't work.

When printing System.getProperties().get("java.library.path") I get the
right paths but still I get the "unsatisfied link error". Is there more
debug information available in some way?

This is really frustrating since it shouldn't be this hard :)

I appreciate any help.
--
Andreas Andersson
IT Dept.
Travelstart Nordic
***@travelstart.se
http://www.travelstart.se
Andreas Andersson
2005-02-02 09:03:09 UTC
Permalink
Has no-one done this?

I think the problem is when the already loaded .so-file wants to load
other .so's. The java.library.path is set correctly but perhaps only for
tomcat and not for the loaded .so.

I've also tried to copy all of the required files to /usr/lib but
without success.
Post by Andreas Andersson
Hi again. I did take a look but nothing helped me there and I still need
help.
My guess is that tomcat has some restrictions when it comes to loading
native code.
I have several native libraries. One of them is loaded and executed from
my code, the rest is used by the first one.
What confuses me is that this works on my tomcat on windows but not
linux. It also works on a standalone program on that same linux machine.
But not my tomcat on linux.
I've tried putting the libraries in /usr/lib. That works for my
standalone but not tomcat.
I've tried setting -Djava.library.path in catalina.sh, that doesn't work.
When printing System.getProperties().get("java.library.path") I get the
right paths but still I get the "unsatisfied link error". Is there more
debug information available in some way?
This is really frustrating since it shouldn't be this hard :)
I appreciate any help.
--
Andreas Andersson
IT Dept.
Travelstart Nordic
***@travelstart.se
http://www.travelstart.se
Loading...