add to tomcat classpath

Posted on 2007-08-10
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?
Question by:bhomass
    LVL 19

    Expert Comment

    by:Jim Cakalic
    The information on this page may be of help to you (not sure which version of Tomcat you're running):

    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.

    Jim Cakalic

    Author Comment

    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?
    LVL 19

    Accepted Solution

    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:, 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:

    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.


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    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 …
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This video teaches viewers about errors in exception handling.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now