LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2012, 01:41 PM   #1
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Unhappy 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.
 
Old 04-10-2012, 03:04 PM   #2
Enrix
Member
 
Registered: Mar 2012
Location: Aguascalientes, mx
Distribution: Opensuse 12.1 x86-64
Posts: 34

Rep: Reputation: 1
Hello Dwhitney67,

Quote:
Originally Posted by dwhitney67 View Post
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.
 
Old 04-10-2012, 03:33 PM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Original Poster
Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by Enrix View Post
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

Last edited by dwhitney67; 04-10-2012 at 03:34 PM.
 
Old 04-10-2012, 03:41 PM   #4
Enrix
Member
 
Registered: Mar 2012
Location: Aguascalientes, mx
Distribution: Opensuse 12.1 x86-64
Posts: 34

Rep: Reputation: 1
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.
 
Old 04-10-2012, 05:03 PM   #5
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Original Poster
Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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
 
  


Reply

Tags
jar, shared, tomcat



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set mail.jar(JavaMail) and mysql-connector-java.jar in Linux class path Terry56 Linux - Software 3 01-19-2010 09:06 AM
I got error with this command 'java -jar NodeView-v1.1.jar' mohdismiaswaly Linux - Software 3 04-23-2009 06:24 AM
how to create shared libraries and configure shared object location vijaya_svk Programming 2 11-19-2007 12:30 PM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 05:26 AM
Using Tomcat to run a .jar file davee Linux - Software 1 08-15-2003 05:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration