You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ml...@planwerk6.de on 2007/07/19 19:53:26 UTC
Maven and jetty classpath
Hi,
i have strange classLoader problem. I use maven, eclipse and jetty.
i want to write a functional test with htmlunit, something like shown here
http://today.java.net/pub/a/today/2007/04/12/embedded-integration-testing-of-web-applications.html
i start a jetty container with
private static Server startServer ( ) throws Exception
{
// 0 means assign any free port
Server server = new Server(0);
server.addHandler(new WebAppContext("target/myproject", ""));
server.start();
// getLocalPort returns the port that was actually assigned
port = server.getConnectors()[0].getLocalPort();
return server;
}
jetty starts up fine.
but now i want to get the WebApplicationContext from the spring like this
WebAppContext jettyCtx = (WebAppContext) server.getHandler();
ServletContext sc = jettyCtx.getServletHandler().getServletContext();
String key = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
System.out.println(sc.getAttribute(key).getClass());
WebApplicationContext ctx = (WebApplicationContext) sc.getAttribute(key);
it prints:
class org.springframework.web.context.support.XmlWebApplicationContext
and throws then a
ClassCastException
But XmlWebApplicationContext IS A WebApplicationContext, so it SHOULD be
castable
The problem is, that i have all my maven dependencies on the classpath (either
running from mvn test or inside eclipse), but jetty seems to use a different
classLoader which loads the classes from WEB-INF/lib
So the XmlWebApplicationContext is from target/WEB-INF/lib ClassLoader and is
in a different "class Loader hierarchie"??
I dont understand much of classloaders. but if i delete all jar files from
WEB-INF/lib, it works fine. I know this question is not directly related to
maven but i don't have any clue how to fix it and where to ask.
I want my testcase to try to load its classes from target/WEB-INF/lib falling
back to maven dependencies.
How can i manipulate the classLoader at runtime and advise it to look first in
WEB-INF/lib ?
any help is very appreciated
kind regards,
janning
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Maven and jetty classpath
Posted by ml...@planwerk6.de.
Am Donnerstag, 19. Juli 2007 19:53 schrieb mljv@planwerk6.de:
> Hi,
>
> i have strange classLoader problem. I use maven, eclipse and jetty.
>
> i want to write a functional test with htmlunit, something like shown here
>
> http://today.java.net/pub/a/today/2007/04/12/embedded-integration-testing-o
>f-web-applications.html
>
> i start a jetty container with
>
> private static Server startServer ( ) throws Exception
> {
> // 0 means assign any free port
> Server server = new Server(0);
> server.addHandler(new WebAppContext("target/myproject", ""));
> server.start();
> // getLocalPort returns the port that was actually assigned
> port = server.getConnectors()[0].getLocalPort();
> return server;
> }
>
> jetty starts up fine.
> but now i want to get the WebApplicationContext from the spring like this
>
> WebAppContext jettyCtx = (WebAppContext) server.getHandler();
> ServletContext sc = jettyCtx.getServletHandler().getServletContext();
> String key =
> WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
> System.out.println(sc.getAttribute(key).getClass());
> WebApplicationContext ctx = (WebApplicationContext)
> sc.getAttribute(key);
>
> it prints:
> class org.springframework.web.context.support.XmlWebApplicationContext
> and throws then a
> ClassCastException
> But XmlWebApplicationContext IS A WebApplicationContext, so it SHOULD be
> castable
i fixed it myself by giving jetty a different directory:
server.addHandler(new WebAppContext("src/main/webapp", ""));
kind regards,
Janning
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org