4

I am using cargo maven plugin for testing purposes. Cargo is used to start our webapp and then REST API tests are run against it. We are using jetty 9.1.1.

I am using cargo version: 1.4.8

Here is the configuration of the cargo plugin:

        <dependencies>
            <dependency>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-core-uberjar</artifactId>
                <version>${cargo.version}</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>${cargo.version}</version>
                    <configuration>
                        <wait>false</wait>
                        <container>
                            <containerId>jetty9x</containerId>
                            <timeout>180000</timeout>
                            <artifactInstaller>
                                <groupId>org.eclipse.jetty</groupId>
                                <artifactId>jetty-distribution</artifactId>
                                <version>${jetty.version}</version>
                            </artifactInstaller>
                        </container>
                        <configuration>
                            <type>standalone</type>
                            <properties>
                                <cargo.servlet.port>${jetty.port}</cargo.servlet.port>
                                <cargo.jvmargs>-Xmx1024m -XX:MaxPermSize=512m</cargo.jvmargs>
                                <cargo.logging>high</cargo.logging>
                            </properties>
                        </configuration>
                        <deployables>
                            <deployable>
                                <groupId>org.codehaus.cargo</groupId>
                                <artifactId>simple-war</artifactId>
                                <type>war</type>
                                <location>${unpacked.war.directory}</location>
                                <properties>
                                    <context>portal</context>
                                </properties>
                            </deployable>
                        </deployables>                              
                    </configuration>
                    <executions>
                        <execution>
                            <id>start-server</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>start</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop-server</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>                                          
                </plugin>                
            </plugins>
        </build>

Our code in one of the servlets uses org.eclipse.jetty.servlet.ServletContextHandler$Context

Since we are running in production with jetty embedded, we configure in the module which uses this in pom.xml with the provided scope for jetty modules.

There are no problems in production.

But when running in cargo, I get the following exception:

java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletContextHandler$Context
at my.package.DefaultServletConfiguration.setServletConfig(DefaultServletConfiguration.java:42)
at my.package.InitServlet.init(InitServlet.java:204)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:612)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:395)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:461)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:321)
at org.eclipse.jetty.start.Main.start(Main.java:817)
at org.eclipse.jetty.start.Main.main(Main.java:112)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.servlet.ServletContextHandler$Context
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at org.eclipse.jetty.webapp.WebAppClassLoader.findClass(WebAppClassLoader.java:510)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:441)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
... 45 more

I also tried to specify the scope as compile for the jetty modules in order them to be in the lib directory inside the webapp, but then seems like there are different class loaders problem. The loader which loads the Context class in webapp is different by the one which jetty is loaded.

What is wrong here?

UPDATE

Same occurs with cargo version 1.4.14 and jetty 9.2.9.v20150224


UPDATE 2

I have tried to put the jetty-servlet in classpath as additional jar dependency as per documentation of cargo maven plugin: here

<container>
    <containerId>jetty9x</containerId>
    <timeout>180000</timeout>
    <artifactInstaller>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-distribution</artifactId>
        <version>${jetty.version}</version>
    </artifactInstaller>
    <dependencies>
        <dependency>
            <artifactId>jetty-servlet</artifactId>
            ...
        </dependency>
    </dependencies>
</container>

Now I see there is a property on the dependency element, which is called classpath, which has 2 values: shared or extra. Default value is extra. I will try shared one, and will check the result.

UPDATE 3

The classpath on container dependency with value shared didn't help. I see that only the following jar visible from within my WebApp (from a servlet):

.../target/cargo/installs/jetty-distribution-9.2.9.v20150224/jetty-distribution-9.2.9.v20150224/start.jar
Genry
  • 1,358
  • 2
  • 23
  • 39
  • can you please post full stack trace – Vinay Lodha Jun 19 '14 at 06:39
  • This kind of error also occurs when the static initialization fails (runtime exception in static block). But seems there are no static blocks in considered classes... – katrin Aug 26 '14 at 15:00
  • added the full exception. It also occurs with cargo version 1.4.14 an jetty 9.2.9 – Genry May 07 '15 at 17:10
  • Have you tried just removing the `provided` from the dependency in question? – Jose Martinez May 07 '15 at 18:36
  • Didn't try it yet. I followed the documentation of cargo maven plugin how to add additional jars into classpath of the application (configured it as dependency in the 'configuration' section of the 'container' - I see that the jar jetty-servlet is brought to the container. But when I enumerate the classpath from within my web application (for debugging) I see that only the 'jetty-start' jar is in there. It is somehow does not appear in the classpath of the webapp. – Genry May 09 '15 at 06:12
  • Another thing is, that the same configuration with Jetty 7.5.4.v20111024 works fine. – Genry May 10 '15 at 14:52
  • In my case, WAR file contains same jar that provided by jetty lib/ext. ClassNotFoundException error caused via spring. After removed the jar from WAR, works fine. – shoma May 19 '15 at 07:04
  • I don't have the jetty jar inside WAR in the first place. And if I put there the same jar, then ClassCastException occurs. Clearly something is wrong with class loaders here. – Genry May 20 '15 at 18:33
  • Thanks everyone. I lost the battle with cargo, and ended with writing a simple extension on the jetty-maven-plugin to run assembled war in forked mode (in another JVM). I did it, because the original jetty-maven-plugin supplies forked mode only in mode of assembling it from various web-app modules. That's why I wanted to use cargo in the first place. – Genry May 21 '15 at 15:33

0 Answers0