users@jersey.java.net

Jersey, Jetty and web.xml

From: Lars Tackmann <ltackmann_at_gmail.com>
Date: Tue, 22 Apr 2008 16:04:09 +0200

Hi

I usually test my web applications using embedded jetty with code such as this:

--
	@BeforeClass
	public void setUp() throws Exception {
		server = new Server(port);
		WebAppContext webAppContext = new WebAppContext("src/main/webapp", "/");
		webAppContext.setConfigurationClasses(new String[] {
				"org.mortbay.jetty.webapp.WebInfConfiguration",
				"org.mortbay.jetty.webapp.WebXmlConfiguration" });
		server.addHandler(webAppContext);
		server.start();
	}
	@AfterClass
	public void tearDown() throws Exception {
		if (server != null)
			server.stop();
	}
--
which forces jetty to look in "src/main/webapp" for my WEB-INF and
then use my programs classpath to pick the needed classes.
This works beautifully with Seam and Struts applications but fails
miserably with Jersey, since it tries to pick up "src/main/webapp"
as the base for my classpath. Resulting in:
--
WARNING: File, C:\projects\randompage\java\samples\jax-rs\bookmarking\src\main\webapp\WEB-INF\lib,
is ignored, it not a directory, a jar file or a zip file
Apr 22, 2008 3:42:13 PM
com.sun.ws.rest.impl.container.config.AnnotatedClassScanner index
WARNING: File, C:\projects\randompage\java\samples\jax-rs\bookmarking\src\main\webapp\WEB-INF\classes,
is ignored, it not a directory, a jar file or a zip file
--
I really like to use web.xml in my unit tests since it frees my of the
redundancy involved in configuring a servlet holder
--
ServletHolder sh = new ServletHolder(ServletContainer.class);
// manually set init parameters below
// :
--
So in short is there some way to get Jersey working from within Jetty
using a existing web.xml ?
Any input will be greatly appreciated.
-- 
Yours sincerely
Lars Tackmann