10
votes

I am trying to host my webapp (spring) in jetty server. I copied my war file to the 'webapp' folder in the jetty server. I am not trying to embed the jetty server, but trying to host the app within the jetty (like tomcat).

I dint install jetty, I just downloaded the jetty7 zip and extracted to get the server.

I need to set this up in 3 linux machines. In One machine the server is starting up just fine.No issues.

But in the other two, when the Server is starting up it is showing the following error.

2013-04-24 18:52:59.540:INFO::started o.e.j.w.WebAppContext{/cpewebapp,file:/tmp/jetty-0.0.0.0-9080-cpewebapp.war-_cpewebapp-any-/webapp/},/home/manooja/jetty-hightide-7.4.0.v20110414/webapps/cpewebapp.war
2013-04-24 18:52:59.648:WARN::FAILED spring: java.lang.NoClassDefFoundError: org/springframework/web/context/support/DefaultWebEnvironment
2013-04-24 18:52:59.648:WARN::FAILED o.e.j.w.WebAppContext{/cpewebapp,file:/tmp/jetty-0.0.0.0-9080-cpewebapp.war-_cpewebapp-any-/webapp/},/home/manooja/jetty-hightide-7.4.0.v20110414/webapps/cpewebapp.war: java.lang.NoClassDefFoundError: org/springframework/web/context/support/DefaultWebEnvironment
2013-04-24 18:52:59.649:WARN::Unable to reach node goal: started
java.lang.NoClassDefFoundError: org/springframework/web/context/support/DefaultWebEnvironment
    at org.springframework.web.servlet.HttpServletBean.(HttpServletBean.java:90)
    at org.springframework.web.servlet.FrameworkServlet.(FrameworkServlet.java:96)
    at org.springframework.web.servlet.DispatcherServlet.(DispatcherServlet.java:128)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at java.lang.Class.newInstance0(Class.java:372)
    at java.lang.Class.newInstance(Class.java:325)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:606)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:748)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:426)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:260)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:763)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:245)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1158)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:587)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:436)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:180)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:482)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:137)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:50)
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:601)
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:531)
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394)
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:329)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:114)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:543)
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:218)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:41)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:50)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:94)
    at org.eclipse.jetty.server.Server.doStart(Server.java:253)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1220)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1143)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:477)
    at org.eclipse.jetty.start.Main.start(Main.java:623)
    at org.eclipse.jetty.start.Main.parseCommandLine(Main.java:273)
    at org.eclipse.jetty.start.Main.main(Main.java:81)
Caused by: 
java.lang.ClassNotFoundException: org.springframework.web.context.support.DefaultWebEnvironment
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:420)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:373)
    at org.springframework.web.servlet.HttpServletBean.(HttpServletBean.java:90)
    at org.springframework.web.servlet.FrameworkServlet.(FrameworkServlet.java:96)
    at org.springframework.web.servlet.DispatcherServlet.(DispatcherServlet.java:128)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at java.lang.Class.newInstance0(Class.java:372)
    at java.lang.Class.newInstance(Class.java:325)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:606)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:748)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:426)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:260)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:763)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:245)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1158)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:587)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:436)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:180)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:482)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:137)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:50)
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:601)
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:531)
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394)
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:329)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:114)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:543)
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:218)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:41)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:50)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:94)
    at org.eclipse.jetty.server.Server.doStart(Server.java:253)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1220)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1143)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:477)
    at org.eclipse.jetty.start.Main.start(Main.java:623)
    at org.eclipse.jetty.start.Main.parseCommandLine(Main.java:273)
    at org.eclipse.jetty.start.Main.main(Main.java:81)
2013-04-24 18:52:59.654:INFO::Deployable added: /home/manooja/jetty-hightide-7.4.0.v20110414/webapps/root
2013-04-24 18:52:59.849:INFO::started o.e.j.w.WebAppContext{/,file:/home/manooja/jetty-hightide-7.4.0.v20110414/webapps/root/},/home/manooja/jetty-hightide-7.4.0.v20110414/webapps/root
2013-04-24 18:52:59.861:INFO::Deployment monitor /home/manooja/jetty-hightide-7.4.0.v20110414/contexts at interval 1
2013-04-24 18:52:59.950:INFO::Started [email protected]:9080 STARTING

Kindly note that the default port have been changed to 9080.

I have an inkling that it might be some configuration change, as it is working fine in one machine. Could you please help me with a guidance to solve this?

java -jar start.jar --version


    Active Options: [Server, client, ext, jmx, jsp, resources, websocket]
    Version Information on 25 entries in the classpath.
    Note: order presented here is how they would appear on the classpath.
          changes to the OPTIONS=[option,option,...] command line option will be reflected here.
     0:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-xml-9.0.2.v20130417.jar
     1:  3.0.0.v201112011016 | ${jetty.home}/lib/servlet-api-3.0.jar
     2:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-http-9.0.2.v20130417.jar
     3:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-continuation-9.0.2.v20130417.jar
     4:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-server-9.0.2.v20130417.jar
     5:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-security-9.0.2.v20130417.jar
     6:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-servlet-9.0.2.v20130417.jar
     7:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-webapp-9.0.2.v20130417.jar
     8:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-deploy-9.0.2.v20130417.jar
     9:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-client-9.0.2.v20130417.jar
    10:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-jmx-9.0.2.v20130417.jar
    11:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/com.sun.el-2.2.0.v201303151357.jar
    12:  2.2.0.v201303151357 | ${jetty.home}/lib/jsp/javax.el-2.2.0.v201303151357.jar
    13:  1.2.0.v201105211821 | ${jetty.home}/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
    14:  2.2.0.v201112011158 | ${jetty.home}/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar
    15:  2.2.2.v201112011158 | ${jetty.home}/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar
    16:  1.2.0.v201112081803 | ${jetty.home}/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
    17: 3.8.2.v20130121-145325 | ${jetty.home}/lib/jsp/org.eclipse.jdt.core-3.8.2.v20130121.jar
    18:                (dir) | ${jetty.home}/resources
    19:      9.0.2.v20130417 | ${jetty.home}/lib/websocket/websocket-api-9.0.2.v20130417.jar
    20:      9.0.2.v20130417 | ${jetty.home}/lib/websocket/websocket-common-9.0.2.v20130417.jar
    21:      9.0.2.v20130417 | ${jetty.home}/lib/websocket/websocket-server-9.0.2.v20130417.jar
    22:      9.0.2.v20130417 | ${jetty.home}/lib/websocket/websocket-servlet-9.0.2.v20130417.jar
    23:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-util-9.0.2.v20130417.jar
    24:      9.0.2.v20130417 | ${jetty.home}/lib/jetty-io-9.0.2.v20130417.jar

dir ./WEB-INF/lib/

antlr-2.7.6.jar
aopalliance-1.0.jar
bcprov-jdk15on-148.jar
c3p0-0.9.1.jar
commons-collections-3.2.1.jar
commons-dbcp-1.3.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
commons-pool-1.5.4.jar
cpewebapp.jar
displaytag-1.2.jar
dom4j-1.6.1.jar
gson-1.6.jar
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core-3.6.4.Final.jar
hibernate-entitymanager-3.6.4.Final.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-validator-4.2.0.Final.jar
jackson-core-asl-1.8.0.jar
jackson-mapper-asl-1.8.0.jar
javassist-3.12.0.GA.jar
json.jar
jta.jar
log4j-1.2.16.jar
servlet-2.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
spring-aop-3.1.0.RELEASE.jar
spring-asm-3.1.0.RELEASE.jar
spring-beans-3.1.0.RELEASE.jar
spring-context-3.1.0.RELEASE.jar
spring-context-support-3.1.0.RELEASE.jar
spring-core-3.1.0.RELEASE.jar
spring-expression-3.1.0.RELEASE.jar
spring-jdbc-3.1.0.RELEASE.jar
spring-ldap-core-1.3.0.RELEASE.jar
spring-ldap-core-tiger-1.3.0.RELEASE.jar
spring-orm-3.1.0.RELEASE.jar
spring-oxm-3.1.0.RELEASE.jar
spring-security-config-3.1.0.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-ldap-3.1.0.RELEASE.jar
spring-security-web-3.1.0.RELEASE.jar
spring-tx-3.1.0.RELEASE.jar
spring-web-3.1.0.RELEASE.jar
spring-webmvc-3.1.0.M1.jar
spring-web-servlet-3.1.0.RELEASE.jar
sqlite-jdbc-3.7.2.jar
velocity-1.6.2.jar
velocity-tools-view-2.0.jar
3
How are you building the war? Looks like org.springframework.web.context.support.DefaultWebEnvironment is missing from the classpath ... perhaps it is (wrongly) on Jetty's classpath on the machine that is working? Is the spring support jar really inside the war?Stevie
I do not want the Jetty to look for this class Something in your code needs the class, that's why java is trying to load it, but can't find it.Sotirios Delimanolis
Exactly what version of Spring are you using? DefaultWebEnvironment appears to only exist in pre-release versions of 3.1.0 (appears it didn't make it into the release). I'd suggest you update to at least a release version of 3.1.x, or better still to the current 3.2.2 ... also DONT put any jars in Jetty's lib directory! (if that's what you meant)Stevie
@user2315838 That's exactly the point. It's needed by some other class you are using internally, but it's missing, so you are getting ClassNotFound. Maybe find which other class is using it.Sotirios Delimanolis
@user2315838 I don't know. Your best bet is figuring out which class uses the DefaultWebEnvironment (look at some javadoc) and figure out why it would use it as default, maybe you can set it to something else.Sotirios Delimanolis

3 Answers

4
votes

As Stevie pointed out in the comments, the issue was an additional Jar file which got into the war.

I removed the Jar, in my case spring-webmvc-3.1.0.M1.jar, from WEB-INF/lib and restarted jetty.It started up fine.

This went unnoticed as it dint show up during compile/build time (got the jar ordered in eclipse), nor did it showed up in the first machine i deployed.

Many thanks for the help.

0
votes

You can change your project config, like I use maven like this page. http://mvnrepository.com/artifact/redis.clients/jedis/2.8.1

Then, when you use "update maven project" in eclipse et, it will download the jedis.jar and other relationship files for complier. It will work in jetty to fix problem.

0
votes

In the case you use directly jetty as Eclipse J2EE integrated server, sometimes, it doesn't find some libraries (I don't understand why some are not found, by only a few), and throws exception of this kind (NoClassDefFound).

  • So you have to put in the project source (directory WEB-INF): your jars

  • restart the server

  • it put the jars in runtime WEB-INF: Data\workspace.metadata.plugins\org.eclipse.wst.server.core\tmpX\MyApp\WEB-INF\lib

  • and it works.