Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Jetty java.lang.NoClassDefFoundError: org/mortbay/log/Log

I'm trying to write a small embedded Jetty program for an app that is normally deployed to Tomcat. My app appears to initialize fine but then the Jetty server start throws an error related to logging. I have a log4j.properties file in my src directory and am including log4j and slf4j-log4j12 as Maven dependencies. Any idea where I've erred?

Thanks!

WARN - FAILED org.eclipse.jetty.server.Server@6b0e9064: java.lang.NoClassDefFoundError: org/mortbay/log/Log
java.lang.NoClassDefFoundError: org/mortbay/log/Log
    at com.sun.org.apache.commons.logging.JettyLog.<init>(JettyLog.java:36)
    at com.sun.org.apache.commons.logging.LogFactory.getLog(LogFactory.java:35)
    at org.apache.jasper.servlet.JspServlet.<clinit>(JspServlet.java:116)
    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:374)
    at java.lang.Class.newInstance(Class.java:327)
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2307)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createInstance(ServletContextHandler.java:1164)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1151)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:976)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:521)
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:810)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1346)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:491)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.server.Server.start(Server.java:355)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.server.Server.doStart(Server.java:324)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at com.foo.rscontrolcenter.ControlCenter.main(ControlCenter.java:19)
    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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Here is my program:

public class ControlCenter {

    public static void main(String[] args) throws Exception {

        Server server = new Server( 8080 );
        WebAppContext root = new WebAppContext("ControlCenter/Website/", "/controlcenter");
        HandlerCollection handlerCollection = new HandlerCollection();

        handlerCollection.addHandler(root);

        server.setHandler(handlerCollection);
        server.start();
    }

}
like image 786
Todd Chapman Avatar asked Nov 12 '22 17:11

Todd Chapman


1 Answers

You choose the wrong JspServlet implementation.

It is looking for org.mortbay.jetty based classes, that's for Old Jetty 6 and earlier.

The Example Project

Look at the jetty-project/embedded-jetty-jsp example on github for a working example of embedded jetty + jsp support.

https://github.com/jetty-project/embedded-jetty-jsp

Pay attention to:

  • The meta-dependency for jetty-jsp in /pom.xml
  • The configuration for JavaC use with Jsp in org.eclipse.jetty.demo.Main
  • The setup of JspServlet in org.eclipse.jetty.demo.Main
  • The setup of Classloaders in org.eclipse.jetty.demo.Main

The Dependencies

Here's the dependency tree in use by that example project

[embedded-jetty-jsp]$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building embedded-jetty-jsp 1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ embedded-jetty-jsp ---
[INFO] org.eclipse.jetty.demo:embedded-jetty-jsp:jar:1-SNAPSHOT
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.1.0.v20131115:compile
[INFO] |  +- org.eclipse.jetty:jetty-xml:jar:9.1.0.v20131115:compile
[INFO] |  |  \- org.eclipse.jetty:jetty-util:jar:9.1.0.v20131115:compile
[INFO] |  \- org.eclipse.jetty:jetty-servlet:jar:9.1.0.v20131115:compile
[INFO] |     \- org.eclipse.jetty:jetty-security:jar:9.1.0.v20131115:compile
[INFO] |        \- org.eclipse.jetty:jetty-server:jar:9.1.0.v20131115:compile
[INFO] |           +- org.eclipse.jetty:jetty-http:jar:9.1.0.v20131115:compile
[INFO] |           \- org.eclipse.jetty:jetty-io:jar:9.1.0.v20131115:compile
[INFO] \- org.eclipse.jetty:jetty-jsp:pom:9.1.0.v20131115:compile
[INFO]    +- org.eclipse.jetty.toolchain:jetty-schemas:jar:3.1.M0:compile
[INFO]    +- javax.servlet.jsp:javax.servlet.jsp-api:jar:2.3.1:compile
[INFO]    +- org.glassfish.web:javax.servlet.jsp:jar:2.3.2:compile
[INFO]    +- org.eclipse.jetty.orbit:javax.servlet.jsp.jstl:jar:1.2.0.v201105211821:compile
[INFO]    +- org.eclipse.jetty.orbit:org.apache.taglibs.standard.glassfish:jar:1.2.0.v201112081803:compile
[INFO]    \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.528s
[INFO] Finished at: Thu Dec 05 11:03:49 MST 2013
[INFO] Final Memory: 12M/484M
[INFO] ------------------------------------------------------------------------
like image 105
Joakim Erdfelt Avatar answered Dec 01 '22 17:12

Joakim Erdfelt