tags:

views:

25

answers:

1

I can't seem to get tomcat to properly set environment variables. I can run my .jar normally with my LD_LIBRARY_PATH set to the correct place, it finds my external libraries just fine. If I unset LD_LIBRARY_PATH and run the jar I get the error:

java.lang.RuntimeException: Native code library failed to load: 
  ensure the appropriate library (opl<VERSION>.dll/.so) is in your path.

which is to be expected.

Anyway, I created a tomcat/bin/setenv.sh script that looks like this:

LD_LIBRARY_PATH=/home/public/lib

But when I run my code over the webservice I still get the same error:

java.lang.RuntimeException: Native code library failed to load: 
  ensure the appropriate library (opl<VERSION>.dll/.so) is in your path.

Any ideas?

+2  A: 
export LD_LIBRARY_PATH

Is what you are missing.

and also perhaps an appropriate addition of -Djava.library.path=MYDIR to the java flags.

bmargulies
Darn, neither of those seemed to help... I also tried copying all my libraries to /usr/share/tomcat6/lib and /lib that didn't seem to work either
anonymous_21321
That certainly won't help. Run with debug turned on and post the messages you see. You are putting the containing dir of the shared libs in those two places?
bmargulies
Are you sure that it's reading setenv.sh at all? Toss an echo command in there.
bmargulies
To expand: if you do `foo=bar` inside of `setenv.sh`, then the setting of `foo` is only valid for the exection of `setenv.sh` itself. Once this shell script is done, `foo` no longer exists. `export foo=bar` makes the variable `foo` (and it's value of `bar`) available to the parent shells/environments.
matt b
@bmargulies - I'm not sure how to turn debug on in tomcat.. And yes I'm sure setenv.sh is running I threw a echo "\n\n\n TEST \n\n\n" in to see.
anonymous_21321
@matt b - Yes I know, this is why I figured I'de give export a try, but all of the setenv.sh examples don't actually use export. probably because they are called from the tomcat startup script and only local variables settings are actually needed
anonymous_21321
to be clear: I have Tomcat servers in which my `setenv.sh` has lines like `export LD_LIBRARY_PATH=foo` and `export JAVA_OPTS=bar`, and it works as I expect. It needs to be `export LD_LIBRARY_PATH=somevalue` or `LD_LIBRARY_PATH=somevalue; export LD_LIBRARY_PATH`; not solely `export LD_LIBRARY_PATH` as the answer might lead you to believe.
matt b