问题描述:

I'm trying to setup an embedded jetty 9 instance which picks up annotations from a .war file.

So far it succeeds in running e.g. GeoServer.war (by setting ExtractWars to True), but I get a ClassNotFound on the AnnotationsConfiguration class when it picks up the WebChat.war which contains an annotated servlet.

In the example war, i added 'metadata-complete="false"' to its web.xml, Also i added the next bit to the jetty server

 ContextHandlerCollection mHandlers = new ContextHandlerCollection();

String mWebAppDir = ... ;

WebAppProvider mAppProvider = new WebAppProvider();

mAppProvider.setMonitoredDirName( mWebAppDir );

mAppProvider.setDefaultsDescriptor( null );

mAppProvider.setScanInterval(0);

mAppProvider.setExtractWars(true);

mAppProvider.setConfigurationClasses( new String[]{

AnnotationConfiguration.class.toString(),

WebInfConfiguration.class.toString(),

PlusConfiguration.class.toString(),

FragmentConfiguration.class.toString(),

});

DeploymentManager mDeployMgr = new DeploymentManager();

mDeployMgr.addAppProvider( mAppProvider );

mDeployMgr.setContexts( mHandlers );

/* Setup & Run server */

mServer.addBean(mDeployMgr);

mServer.setHandler(mHandlers);

mServer.start();

I added all Jetty9 jars (jetty-distribution-9.0.3.v20130506), including the jar 'websocket-core-9.0.0.M2.jar' to the jetty server project. The IDE knows AnnotationConfiguration class, but when jetty processes the war file, it comes with:

2013-07-16 14:05:36.731:INFO:oejs.Server:main: jetty-9.0.3.v20130506

2013-07-16 14:05:36.753:INFO:oejdp.ScanningAppProvider:main:

Deployment monitor [file:/C:/..../webapps/] at interval 0

2013-07-16 12:57:38.542:WARN:oejw.WebAppContext:main:

Failed startup of context [email protected]{/WebChat,null,null}

{C:\....\webapps\WebChat.war}

java.lang.ClassNotFoundException: class org.eclipse.jetty.annotations.AnnotationConfiguration

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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

at org.eclipse.jetty.util.Loader.loadClass(Loader.java:100)

at org.eclipse.jetty.util.Loader.loadClass(Loader.java:79)

at org.eclipse.jetty.webapp.WebAppContext.loadConfigurations(WebAppContext.java:919)

at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:420)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)

at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:39)

at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)

at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:495)

at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)

at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:175)

at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)

at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:605)

The WebChat.war contents is as follows:

\chat.html

\css\style.css

\js\jquery-1.3.2.js

\META-INF\MANIFEST.MF

\WEB-INF\classes

\WEB-INF\lib

\WEB-INF\web.xml

\WEB-INF\classes\jettytest

\WEB-INF\classes\jettytest\Feature.class

\WEB-INF\classes\jettytest\FeatureWebSocket.class

\WEB-INF\classes\jettytest\FeatureWebSocketServlet.class

\WEB-INF\lib\websocket-api-9.0.3.v20130506.jar

\WEB-INF\lib\websocket-common-9.0.3.v20130506.jar

\WEB-INF\lib\websocket-core-9.0.0.M2.jar

\WEB-INF\lib\websocket-server-9.0.3.v20130506.jar

\WEB-INF\lib\websocket-servlet-9.0.3.v20130506.jar

Hoping to get a clue how to solve the classloading issue..

Thanks in advance

网友答案:

Thanks for viewing my question.

I found the problem;

I was running the jetty server only on port 8443, not on 8080. But the webchat.html file initialized using

$(document).ready(
function() {
      ws = new WebSocket("ws://localhost:8443/WebChat/map");

But it should be the WSS protocol, since it's secure via 8443. i.e.

$(document).ready(
function() {
      ws = new WebSocket("wss://localhost:8443/WebChat/map");

Turns out it works WITHOUT setting the setConfigurationClasses as

  mAppProvider.setConfigurationClasses( new String[]{
    AnnotationConfiguration.class.toString(),
    WebInfConfiguration.class.toString(),
    PlusConfiguration.class.toString(),
    FragmentConfiguration.class.toString(),            
  });

Hope someone is helped with this.

相关阅读:
Top