wjw465150 / run-jetty-run

Automatically exported from code.google.com/p/run-jetty-run
0 stars 0 forks source link

Failure to load filters defined in dependent projects #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Something that worked in 1.0.1, but does not work in 1.1.1. I have a set of
maven modules. One of them is webapp (1), another one contains some shared
classes (2). When a web.xml located in (1) declares a filter located in (2)
I get the following error:

Failed startup of context
org.mortbay.jetty.webapp.WebAppContext@6c2896{/context,src/main/webapp}
javax.servlet.UnavailableException: com.example.MyFilter
    at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:79)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:81)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
    at
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:589)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
    at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1216)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:509)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:447)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
    at runjettyrun.Bootstrap.main(Bootstrap.java:76) 

The same exact projects work under 1.0.1

Original issue reported on code.google.com by aadamc...@gmail.com on 16 Oct 2009 at 7:21

GoogleCodeExporter commented 9 years ago
I should also mention, this is Eclipse 3.4.1 (as well as 3.5.1RC1) on OS X, 
m2eclipse
plugin v. 0.9.8. And this is not limited to the filters. In webapps without 
filters I
am getting errors about various missing resources from related projects.

Original comment by aadamc...@gmail.com on 16 Oct 2009 at 7:39

GoogleCodeExporter commented 9 years ago
I am surprised by this report as I've used just such an arrangement.  Would you 
be 
willing to create a small sample that demonstrates the problem?  The web app 
doesn't 
have to do anything interesting, just demonstrate the failure to locate the 
filters and 
resources.

Original comment by James.Sy...@gmail.com on 17 Oct 2009 at 12:21

GoogleCodeExporter commented 9 years ago
Things look a bit random in my tests. When I tried to reproduce the issue as
originally reported, a vanilla project with a filter in a dependency jar worked.
Either it is now masked by another issue below, or I got stale plugins after a 
few
run-jetty-run (un/re)installs yesterday.

Anyways, today I started fresh with rjr 1.1.1 (starting Eclipse with "-clean"). 
And
now I am consistently getting a java.lang.NoClassDefFoundError on an attempt to
dynamically load a class inside Servlet.init(). I attached a simple test 
project. The
project itself does not have any Eclipse project dependencies. I reduced it to 
bare
minimum. The case is a bit unusual, but nevertheless it works with 1.0.1. The 
class I
am loading is not a maven dependency of the project, but rather from a jar 
added in
Eclipse to the Run Configuration via "Run Configurations.. > XYZ Jetty Config >
Classpath" (the jar file - cayenne-modeler-3.0M6.jar is also included in the
download). The exception thrown is complaining about the interface implemented 
by the
class in question. Interface itself is available as a Maven dependency 
everywhere
else in the project, just not to the dynamically loaded class. So there's some
cross-ClassLoader issue going on. 

The code looks like this:

MyServlet extends HttpServlet {

public void init(ServletConfig config) throws ServletException {
        super.init(config);

        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        Object object = Class
                    .forName("org.example.MyClass", true, loader).newInstance();
}

The stack trace is this:

java.lang.NoClassDefFoundError: org/apache/cayenne/conf/DataSourceFactory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:352)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at org.example.framework.MyServlet.init(MyServlet.java:19)

Original comment by aadamc...@gmail.com on 19 Oct 2009 at 7:22

GoogleCodeExporter commented 9 years ago

Original comment by aadamc...@gmail.com on 19 Oct 2009 at 7:23

Attachments:

GoogleCodeExporter commented 9 years ago
I think it's kind of wrong usage,
we should make it more clear for this defect in future.

In the classpath of Jetty Run-Configuration, 
it's for the *Jetty Web Server* , not for the web application project.

So if you want to use it in web application project , 
it's better to add the external jar to project build Libraries.

I will check the view and the rule , to check if we could do something to make 
it better. :P

Original comment by tonylovejava on 11 Mar 2011 at 9:06

GoogleCodeExporter commented 9 years ago

Original comment by tonylovejava on 20 Mar 2011 at 5:51

GoogleCodeExporter commented 9 years ago
It's better to have a doucment talking the different for the classpath provider 
in run configuration and the classpath for the webapp project.

Original comment by tonylovejava on 22 Mar 2011 at 5:13

GoogleCodeExporter commented 9 years ago
Try to write a document , hope we get it clear enough. :-|

[Classpath]

Original comment by tonylovejava on 4 May 2011 at 3:29