1

When I start server with jetty, the console will display this error information:

Can someone help me ? 3Q.

[2014-10-26 14:11:02  WARN org.eclipse.jetty.util.component.AbstractLifeCycle:204] FAILED org.eclipse.jetty.server.handler.HandlerCollection@3bbbbafc:
java.lang.NoSuchMethodError:    javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
at org.apache.jasper.runtime.TldScanner.onStartup(TldScanner.java:231)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:106)
at org.eclipse.jetty.annotations.ServletContainerInitializerListener.contextInitialized(ServletContainerInitializerListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:775)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:767)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:280)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.runner.Runner.run(Runner.java:512)
at org.mortbay.jetty.runner.Runner.main(Runner.java:633)
[2014-10-26 14:11:02  WARN org.eclipse.jetty.util.component.AbstractLifeCycle:204] FAILED org.eclipse.jetty.server.Server@549b6220: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
at org.apache.jasper.runtime.TldScanner.onStartup(TldScanner.java:231)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:106)
at org.eclipse.jetty.annotations.ServletContainerInitializerListener.contextInitialized(ServletContainerInitializerListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:775)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:767)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:280)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.runner.Runner.run(Runner.java:512)
at org.mortbay.jetty.runner.Runner.main(Runner.java:633)
Exception in thread "main" java.lang.NoSuchMethodError: javax.servlet.ServletContext.getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;
at org.apache.jasper.runtime.TldScanner.onStartup(TldScanner.java:231)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:106)
at org.eclipse.jetty.annotations.ServletContainerInitializerListener.contextInitialized(ServletContainerInitializerListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:775)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:767)
at  org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:280)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.runner.Runner.run(Runner.java:512)
at org.mortbay.jetty.runner.Runner.main(Runner.java:633)
Disconnected from the target VM, address: '127.0.0.1:50852', transport: 'socket'
ivan.sim
  • 8,972
  • 8
  • 47
  • 63
jinkai xu
  • 11
  • 1
  • 3
  • what's the version of jetty and servlet/servlet-api jar seems mismatch between the two. – SMA Oct 26 '14 at 06:24
  • Er... As U know, I use IntelliJ IDE and install a plugin which be called "IDEA Jetty Runner" and the version is 0.0.5. The servlet-api version is 2.5. Tha's all. – jinkai xu Oct 26 '14 at 06:35

2 Answers2

3

The error...

java.lang.NoSuchMethodError: javax.servlet.ServletContext.
   getServletRegistration(Ljava/lang/String;)Ljavax/servlet/ServletRegistration;

Is telling you the key piece of information.

Namely that your startup can't find the method ServletContext.getServletRegistration(String)

Looking at the javadoc, we can see that method was added in Servlet API 3.0.

Looking at your stacktrace we can see that you are using Jetty (a version between 7.0 and 9.0), along with JSPs, via the Jetty Runner bootstrap.

Your server configuration is bad, as its not using the correct Servlet API version, this is not the fault of the Jetty Runner component that the Jetty project maintains, as that comes with the correct Servlet API version built-in. However, either your IDEA setup, your IDEA Jetty Runner Plugin configuration, or your project is downgrading the Servlet API version with its own jar (at the server level).

The Jetty process is in the middle of configuring the WebAppContext by executing the various ServletContextInitializer entries it has found. In this particular case, JSP is being executed to allow it to configure the JSP support for your webapp. It is at this point where you hit the error.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
3

I am the developer of the plugin that you're using. :)
Here is the GitHub link to the plugin / project: IDEA Jetty Runner

As you can see on the "Command Line" implementation I will use the plugin provided jetty-runner jar to start up the jetty server. Here is the link to the class: Jetty Runner Command Line

The reason why I did that is because IntelliJ already provides a great built in plugin that supports multiple versions of Jetty on their Enterprise edition version of the IDE. Also, they have a team behind it to deal with all sorts of bugs / problems that this may cause.

Meanwhile this plugin has been developed in my spare time and made it available for free so people could at least have a lightweight Java EE server on the "Community Edition" version of the IDE and to keep it fair I've decided to limit it to a specific version of jetty / servlet-api.

So, back to your question; what Joakim said here is correct, the plugin downgrades your app to the servlet-api-2.5, in other words downgrade your project to use the servlet-api-2.5 and you should be fine.
"However, either your IDEA setup, your IDEA Jetty Runner Plugin configuration, or your project is downgrading the Servlet API version with its own jar (at the server level)."

You can find a little bit more about the plugin on github.
By the way, thanks for using the plugin! ;)

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
Gui Keller
  • 122
  • 10
  • 1
    Quick update: the plugin is now compatible with servlet-api versions 3.1, 3.0, 2.5, 2.4, 2.3, 2.2 - have fun! – Gui Keller Dec 11 '14 at 22:42