Reputation: 2105
I'm having problems trying to get a Spring 3.1 Framework webapp using the Servlet 3.0 programmatic way to register the servlet running using the Jetty maven plugin.
Here is my maven plugin definition (specifies an override webdefault.xml that has the default servlet mapping removed):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.1.v20120215</version>
<configuration>
<systemProperties>
<systemProperty>
<name>DEBUG</name>
<value>TRUE</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>0</scanIntervalSeconds>
<webAppConfig>
<defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor>
</webAppConfig>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
</configuration>
</plugin>
Here's my cut-down webapp:
public class GcpWebApplicationInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext root =
new AnnotationConfigWebApplicationContext();
root.scan();
servletContext.addListener(new ContextLoaderListener(root));
ServletRegistration.Dynamic servlet = servletContext.addServlet("TESTSERVLET", new DispatcherServlet(root));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
The commannd line I use to run this up is:
mvn -U clean package jetty:run-war
with the following output (just the run-war part):
[INFO] Configuring Jetty for project: GCP Jetty
[INFO] Context path = /
[INFO] Tmp directory = /Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/tmp
[INFO] Web defaults = src/main/resources/webdefault.xml
[INFO] Web overrides = none
2012-03-16 17:09:25.668:INFO:oejs.Server:jetty-8.1.1.v20120215
2012-03-16 17:09:25.691:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war!/ to /Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT
2012-03-16 17:09:27.068:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
2012-03-16 17:09:30.925:INFO:/:No Spring WebApplicationInitializer types detected on classpath
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:09:31.233:INFO:oejs.AbstractConnector:Started [email protected]:8080
[INFO] Started Jetty Server
As you can see it detected the Spring servlet SpringServletContainerInitializer but that servlet didn't detect the GcpWebApplicationInitializer. BUT if I take the war file and manually put it under a standalone Jetty it will detect the GcpWebApplicationInitializer.
Shanes-MacBook-Pro:bin srowatt$ ./jetty.sh run
Running Jetty:
2012-03-16 17:26:21.051:INFO::Redirecting stderr/stdout to /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/logs/2012_03_16.stderrout.log
2012-03-16 17:26:21.353:INFO:oejs.Server:jetty-8.1.1.v20120215
2012-03-16 17:26:21.371:INFO:oejdp.ScanningAppProvider:Deployment monitor /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps at interval 1
2012-03-16 17:26:21.379:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war
2012-03-16 17:26:21.452:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war!/ to /private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp
2012-03-16 17:26:23.976:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:23.976:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:24.215:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war
2012-03-16 17:26:24.216:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war
2012-03-16 17:26:24.216:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war
2012-03-16 17:26:24.466:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root
2012-03-16 17:26:24.576:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:24.576:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root
2012-03-16 17:26:24.583:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:26:24.602:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war!/ to /private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp
2012-03-16 17:26:29.305:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:29.305:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager
2012-03-16 17:26:29.314:INFO:g0.1-SNAPSHOT:Spring WebApplicationInitializers detected on classpath: [com.gcpgroup.jetty.GcpWebApplicationInitializer@11767553]
2012-03-16 17:26:30.362:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:26:30.363:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:26:30.363:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:26:30.363:INFO:g0.1-SNAPSHOT:Initializing Spring root WebApplicationContext
2012-03-16 17:26:30.495:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war
2012-03-16 17:26:30.498:INFO:g0.1-SNAPSHOT:Initializing Spring FrameworkServlet 'TESTSERVLET'
Also if I use mvn -U clean package jetty:run then it will also detect the GcpWebApplicationInitializer as it should.
So why is the jetty:run-war not behaving as I expect? Initially I thought it was the jetty plugin causing the issue but now I think it's more of a Spring issue or classpath issue.
Upvotes: 2
Views: 5958
Reputation: 7958
We are using a similar setup with spring 3.1 & jetty 8. Our config is:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
</webApp>
<jettyConfig>src/main/resources/jetty.xml</jettyConfig>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>file://${project.basedir}/src/main/conf/target/generated-resources/log4j.xml</value>
</systemProperty>
<systemProperty>
<name>env</name>
<value>${env}</value>
</systemProperty>
</systemProperties>
<stopKey>I_CANT_STAND_IT_ANYMORE</stopKey>
<stopPort>54124</stopPort>
</configuration>
</plugin>
You need maven 3.x, with maven 2 you'll end up with a jetty that is not servlet 3.0 compatible.
Upvotes: 1