From: Barzilai S. <ba...@in...> - 2005-09-26 08:55:48
|
Eric, about a year ago I had this same problem, where some webapps should add certain paths to their classloader which were outside the normal WEB-INF/classes and WEB-INF/lib et al. I tried using the addClassPath method of a WebApplicationContext through the jetty.xml files but it didn't work very well. I don't remember the details, but at a certain poing during initialization the classpath would be reset by some of the jetty code. I asked here in the list and Greg gave me some answers (which I won't look up now at 5:40am) but they weren't a complete solution either. I have been working with jetty-5.1.2 so these issues may be solved by now. I don't know if my solution is 100% kosher, or best-practice, or greg-wilkins-approved, but it works quite well :-) The solution I came up with is the following: I wrote an org.mortbay.jetty.servlet.WebApplicationContext.Configuration In the main jetty.xml, where you configure the ...jetty.Server you put this: <Set name="WebApplicationConfigurationClassNames"> <Array type="java.lang.String"> <Item>org.mortbay.jetty.servlet.XMLConfiguration</Item> <Item>org.mortbay.jetty.servlet.JettyWebConfiguration</Item> <Item>net.kalio.utils.jetty.ClassPathConfiguration</Item> </Array> </Set> The last item is the configuration class I wrote. This configuration (or configurator) looks for a file in the webapp's WEB-INF called jetty-extracp.xml (for "extra classpath") which must have the following general syntax: <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.2//EN" "http://jetty.mortbay.org/configure_1_2.dtd"> <Configure class="org.mortbay.jetty.servlet.WebApplicationContext"> <Call name="addClassPath"> <Arg>/my/extra/class/path/</Arg> </Call> ... </Configure> So each time the webbapp is [re]started, it will apply all these extra classpaths to the webapp's main ClassLoader (which already contains the usual classes and lib and all that is common to all webapps). The <Arg> can be directory classpaths (must end with a slash) or paths to a jar file. You can check the complete classpath that your webapp is using by logging in to the Jetty Admin (if you have started it) Attached, you will find the code to my class which I'm happily donating to the Jetty community. DISCLAIMER: This code is only for Jetty, "around" version 5.1.x It may not work in older or newer versions of Jetty, and it will certainly NOT work with Tomcat or other servlet containers. YOUR KILOMETRAGE MAY VARY VERILY! BarZ I wrote Eric Rizzo wrote: > I didn't find anything about this in the message archives, but feel > free to point me to any previous discussions if they exist. > > I need to include an extra directory on the classpath for my webapp. I > thought I could use a META-INF/MANIFEST.MF file like the following to > do it: > > Manifest-Version: 1.0 > Class-Path: WEB-INF/config > > > Unfortunately, this does not work. > My webapp directory structure looks like this: > > webapp/ > META-INF/ > MANIFEST.MF > WEB-INF/ > web.xml > classes/ > <classes in package directories> > lib/ > <some JARs> > config/ > log4j.xml > <other files> > > > I am testing by using log4j.xml, which log4j must find on the > classpath in order to successfully configure itself. When using the > manifest file above, log4j still complains that it can't find the > config file. > > Was I wrong in assuming that the Class-Path entry in a manifest file > applies to a webapp (exploded WAR) as it does to an EAR or JAR? If so, > is there any other way to get my own directory on the webapp classpath > (even Jetty-specific options are open to me). If manifest file is the > way to go, any clue as to what I'm doing wrong? > > TIA, > Eric > |