?
Solved

add to tomcat classpath

Posted on 2007-08-10
4
Medium Priority
?
2,960 Views
Last Modified: 2013-11-05
I am setting up a tomcat project for remote debugging by eclipse. I am able to set up the docbase using a <projectname>.xml ok. however, this project references a lib which I am debugging at the same time, and sits in another directory entirely.

when using eclipse wtp, it is able to somehow have tomcat access both the project and lib code. but when using tomcat directly, I don't know how to get tomcat to find code other than what is under WEB-INF/classes.

can someone explain how to add such a classpath?
0
Comment
Question by:bhomass
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 19756044
The information on this page may be of help to you (not sure which version of Tomcat you're running):
http://tomcat.apache.org/tomcat-5.0-doc/class-loader-howto.html

There are a number of classloaders involved in loading an application server and deployed web applications. The intent is to have control over which classes are shared and by whom. Of the 6 classloaders involved in running Tomcat, only the System classloader uses the classpath. However, the Tomcat startup scripts ignore the classpath environment variable so you can't just the variable, you have to change the startup scripts. Read the document. It is important to understand the classloading structure of your application server.

Tomcat 5.0 and 5.5 use the same classloading hierarchy. Tomcat 6.0's is slightly simpler.

Regards,
Jim Cakalic
0
 

Author Comment

by:bhomass
ID: 19787754
I am not able to figure out how eclipse managed to load the dependent project classpath from your instructions and reading the tomcat doc. my version is 5.5, btw.

according to the doc, webappx is the classloader, I want to use for the dependent jar. there is no instruction on how to add a jar to this class loader, if it is not in the WEB-INF/classes or WEB-INF/lib. but, clealry, that is what eclipse wtp managed to do.

you mentioned changing the startup script, which would be catalina.bat. but nothing is the doc tells me how to modify it so that the additional jar gets picked up by webappx class loader.

what is missing here?
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 150 total points
ID: 19792265
OK. I understand now.

What I believe happens is that Eclipse uses a specialloader for this purpose. AFAIK, the default Tomcat WebAppClassLoader can't be configured externally. It is hardwired to use WEB-INF/classes and WEB-INF/lib only. It's probably that way because that's where the servlet spec says the web application class loader should look. But there's hope ...

If you look here: http://tomcat.apache.org/tomcat-5.5-doc/config/loader.html, you'll find that you can specify a Loader element in the Context configuration. The Loader element "represents the web application classloader for your application". It isn't the classloader itself but is Tomcat's way of configuring the web app classloader. Unfortunately, that doesn't allow you to specify additional resources. But you can extend the WebappLoader Tomcat uses by default and then add in behavior to configure the real classloader with additional paths.

As an example, here's how they're doing this in Tomcat 6:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java?view=markup

Now it may be possible, though I can't guarantee it, that you can use this class as is with Tomcat 5.5. The whole framework for this has existed for a long time. If nothing else, it should be a reasonable bootstrap for what you want to do.

Regards,
Jim
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question