LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can I configure Tomcat to use a shared JAR? (https://www.linuxquestions.org/questions/programming-9/how-can-i-configure-tomcat-to-use-a-shared-jar-939131/)

dwhitney67 04-10-2012 01:41 PM

How can I configure Tomcat to use a shared JAR?
 
I have a servlet application that runs fine under Tomcat, but only if I place a particular JAR file in its WEB-INF/lib directory.

If I attempt to reference this same JAR in its installed location (elsewhere on my system), or even slap it into $CATALINA_HOME/shared/lib, the servlet dies.

I've attempted specifying the JAR file by these following techniques, which I gleaned from Googling, but to no avail.

1) Edit conf/catalina.properties with something like this:
Code:

shared.loader=file:/path/to/MyFile.jar
2) I tried placing the JAR file in shared/lib, thus making the shared.loader specification this:
Code:

shared.loader=file:${catalina.home}/shared/lib/MyFile.jar
3) I created a setenv.sh file in $CATALINA_HOME/bin, which contained the following:
Code:

CLASSPATH=/path/to/MyFile.jar
In case 3 above, this appeared to be the most promising since the class path showed up in the output startup.sh produces, but still my servlet died.

Is there something else that I'm missing? There's not any helpful log information in catalina.out to go by. Again, from what I read while Googling, it is probably due to a ClassNotFound exception.

Enrix 04-10-2012 03:04 PM

Hello Dwhitney67,

Quote:

Originally Posted by dwhitney67 (Post 4649509)
I have a servlet application that runs fine under Tomcat, but only if I place a particular JAR file in its WEB-INF/lib directory.

You can put your jar file on any directory in the system, but seems you're doing something wrong.

Do you use Catalina to boot up tomcat? if not, you should use some other methods.

Quote:

I've attempted specifying the JAR file by these following techniques, which I gleaned from Googling, but to no avail.

1) Edit conf/catalina.properties with something like this:
Code:

shared.loader=file:/path/to/MyFile.jar
2) I tried placing the JAR file in shared/lib, thus making the shared.loader specification this:
Code:

shared.loader=file:${catalina.home}/shared/lib/MyFile.jar
3) I created a setenv.sh file in $CATALINA_HOME/bin, which contained the following:
Code:

CLASSPATH=/path/to/MyFile.jar

Using your 3rd method, the file may exist, but, if is not referenced on tomcat start up, it will be ignored...

Could you try this:
1. if tomcat is running, stop it
2. Put your jar files inside the lib folder under the tomcat directory
3. restart tomcat
4. test your servlet

that directory (tomcat/lib) is where i put any shared library. Let us know if this solution works for you.

dwhitney67 04-10-2012 03:33 PM

Quote:

Originally Posted by Enrix (Post 4649569)
Hello Dwhitney67,


You can put your jar file on any directory in the system, but seems you're doing something wrong.

Do you use Catalina to boot up tomcat? if not, you should use some other methods.



Using your 3rd method, the file may exist, but, if is not referenced on tomcat start up, it will be ignored...

Could you try this:
1. if tomcat is running, stop it
2. Put your jar files inside the lib folder under the tomcat directory
3. restart tomcat
4. test your servlet

that directory (tomcat/lib) is where i put any shared library. Let us know if this solution works for you.

Hi Enrix,

I tried your suggestion, but still no joy.

Is there any way to get more log information from my servlet? Typically when I run it as a non-servlet, I would see a stack trace dump if it failed to start due to a ClassNotFoundException. However, in the 'catalina.out' log, all I see are messages indicating that the servlet started, but nothing indicating why it failed.


P.S. I start Tomcat using $CATALINA_HOME/bin/startup.sh

Enrix 04-10-2012 03:41 PM

the default site for logs is tomcat/logs, there you will have some log files like catalina / host manager / localhost / stderr / stdout... you may check all files for stack trace.

dwhitney67 04-10-2012 05:03 PM

Enrix,

I looked at the "localhost" log file in $CATALINA_HOME/logs, and it indeed indicated that my application was having trouble loading a JNI library (because already loaded), and if I changed a thing or two, then the log indicated that a class could not be found, etc.

I used to place my JNI library (and other project related libraries) in $CATALINA_HOME/bin, but it seems to me that they are better off in $CATALINA_HOME/lib (Thank you for that suggestion).

As for the JAR file, I've placed it in WEB-INF/lib for now. If I attempt to place it in $CATALINA_HOME/lib, I continue to get the following error:
Code:

java.lang.UnsatisfiedLinkError: Native Library /home/me/Tomcat/apache-tomcat-7.0.27/lib/libacme_jni.so already loaded in another classloader


All times are GMT -5. The time now is 10:19 PM.