add to tomcat classpath

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?
bhomassAsked:
Who is Participating?
 
Jim CakalicSenior Developer/ArchitectCommented:
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
 
Jim CakalicSenior Developer/ArchitectCommented:
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
 
bhomassAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.