• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Query regarding Classpath in Tomcat

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to understand how the classpath in tomcat can be modified to point to external directory.


I have a web application, say W that is deployed in tomcat. When I hit an API provided by W, the flow takes me to a jar, say A present in $CATALINA_HOME/lib, which internally calls another jar's API say B.jar.

The issue that I need to debug is that B.jar is present at two paths, i.e , at $CATALINA_HOME/lib and an external directory (outside context of tomcat", say /my/lib/.

When A calls B.jar it first picks the jar from external directory even when B.jar is present in $CATALINA_HOME/lib.

I have checked catalina.properties, for common and shared class loader libraries but I could n't B.jar anywhere specified.

Is there any way via which we can set custom libraries in Tomcat classpath ahead of libraries present in tomcat context?

How can I check the classpath being used by A.jar where external directory has been set by default for all other jars as well?


Please help!.
 
Saloon Keeper
Posts: 28665
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Mani!

Web applications have different classpath considerations than stand-alone apps. Webapps are supposed to be self-contained (write-once/deploy anywhere - more or less).

For the most part, if you want a library to be available to a webapp, it should be part of the webapp. That is, included in the WEB-INF/lib directory.

The $CATALINA_HOME/lib directory should not be supplying webapp resources. It is where the actual Tomcat server components live, including the JDBC drivers and other systemwide resources.

An external directory would not be appropriate at all.
 
Mani Shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I understand that. But in my project, jar is being picked up from external directory (not from $CATALINA_HOME/lib or WEB-INF/lib). From the code of A.jar which is present in $CATALINA_HOME/lib, I have displayed the path of full path B.jar from where it is being picked up and that comes out be external directory.

When I remove B.jar from external directory, it is then picked from $CATALINA_HOME/lib since B.jar is now present only the later.

I wanted to debug and understand that how external directory is being set in the classpath of webapp since there is no classpath mentioned in MANIFEST file of A.jar.
 
Tim Holloway
Saloon Keeper
Posts: 28665
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Debugging is one thing. Messing around with the JEE specs is another.

It is possible that your webapp is implementing a custom classloader that is doing this. You could determine that by doing a Class.forName on the offending class near where it is being instantiated or referenced and using its getClassLoader to find out.

It is also possible that something is messing with the standard classloader classpath. You should be able to print that path out from System.properties. Again, the best place is near where the problem manifests.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual Tomcat installation includes an excellent "class-loader-howto.html" page that explains how Tomcat decides to look for classes.

In the Tomcat versions I am familiar with, the system environment CLASSPATH variable is totally ignored. This is a feature that helps the developer experiment with different Java versions.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic