我正在尝试设置一个嵌入式jetty 9实例,该实例从.war文件中获取注释。
到目前为止它成功运行,例如GeoServer.war(通过将ExtractWars设置为True),但是当它选择包含带注释的servlet的WebChat.war时,我在 AnnotationsConfiguration 类上得到 ClassNotFound 。
在示例战中,我将'metadata-complete =“false”'添加到其web.xml中,同时我将下一位添加到jetty服务器
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();
我在Jetty服务器项目中添加了所有Jetty9 jar(jetty-distribution-9.0.3.v20130506),包括jar'websocket-core-9.0.0.M2.jar'。 IDE知道 AnnotationConfiguration 类,但是当jetty处理war文件时,它会附带:
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 o.e.j.w.WebAppContext@3ac8e6{/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)
WebChat.war 内容如下:
\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
希望得到如何解决类加载问题的线索。
提前致谢
答案 0 :(得分:2)
感谢您查看我的问题。
我发现了问题;
我在端口8443上运行jetty服务器 ,而不是在8080上运行。但是使用
初始化了webchat.html文件$(document).ready(
function() {
ws = new WebSocket("ws://localhost:8443/WebChat/map");
但它应该是WSS协议,因为它通过8443安全。即
$(document).ready(
function() {
ws = new WebSocket("wss://localhost:8443/WebChat/map");
原来它无法将 setConfigurationClasses 设置为
mAppProvider.setConfigurationClasses( new String[]{
AnnotationConfiguration.class.toString(),
WebInfConfiguration.class.toString(),
PlusConfiguration.class.toString(),
FragmentConfiguration.class.toString(),
});
希望有人对此有所帮助。