Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including external jar in Tomcat ClassPath

Tags:

java

tomcat

In Tomcat I want to use a jar inside a web application. The jar file will exist outside of the Tomcat directory.

To include the jar file in tomcat classpath, I modified the TomcatHome/conf/catalina.properties to include the absolute path of my jar file like,

shared.loader=D:\jaa\MyJarFile.jar

as per the suggestion given in link,

http://www.mulesoft.com/tomcat-classpath

But it throws the error,

java.lang.NoClassDefFoundError

I have also tried ,

shared.loader=D:\jaa\*.jar

shared.loader=file:\\D:\jaa\MyJarFile.jar

None of them seem to work :(

If I try placing the jar inside tomcat/lib it seem to work. But I am not allowed to do that.

Please help me out with this issue as I have implementation the next week..

like image 442
Sathesh Avatar asked May 28 '11 18:05

Sathesh


People also ask

Where do I put JAR files in tomcat?

Package the JAR file in the WEB-INF\lib folder of the Java web application; Place the JAR file in the \lib subfolder of the Apache Tomcat installation; Configure a folder for shared JAR files by editing Tomcat's common.

What is Tomcat classpath?

A classpath is an argument that tells the JVM where to find the classes and packages necessary to run a program. The classpath is always set from a source outside the program itself.


1 Answers

I figured myself how to add the classpath for tomcat. Instead of editing catalina.properties, just create a "setenv.sh" in the Tomcat Bin directory with the classpath,

Example,

CLASSPATH=D:\jaa\MyJarFile.jar

I just checked the catalina.sh in Tomcat/bin and these classpath variable will be set while setting the bootstrap as the classpath.

like image 88
Sathesh Avatar answered Sep 28 '22 12:09

Sathesh