嵌入jetty服务器问题
我在将 jetty 服务器嵌入到 java 应用程序中时遇到了一些困难。我正在使用 spring 来配置实际对象,并且我可以毫无问题地构建 web 应用程序 - 但在启动服务器时遇到这个问题...
0 [main] INFO test.Server - Starting server in 'c:/workspace/test/war/' on port 9090
34615 [main] INFO test.Server - Using resource base: src/main/webapp
34615 [main] INFO test.Server - Using descriptor file: src/main/webapp/WEB-INF/web.xml
2011-09-05 12:29:36.961:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
36344 [main] INFO test.Server - Starting Server!
2011-09-05 12:29:37.023:INFO::jetty-6.1H.22
2011-09-05 12:29:37.039:WARN::Failed startup of context org.mortbay.jetty.webapp.WebAppContext@8ab708{/TestServer,file:/C:/workspace/test/war/src/main/webapp/}
java.lang.ClassNotFoundException: org.mortbay.jetty.plus.webapp.EnvConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.mortbay.util.Loader.loadClass(Loader.java:91)
at org.mortbay.util.Loader.loadClass(Loader.java:71)
at org.mortbay.jetty.webapp.WebAppContext.loadConfigurations(WebAppContext.java:859)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:431)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at test.Server.main(Server.java:84)
2011-09-05 12:29:37.054:INFO::Started [email protected]:9090
问题似乎出在我的一些路径内容上...目录结构是直的前进(maven“推荐”)
-workspace/test/war/ -src/main/java/test/Server.java -src/main/webapp/WEB-INF/web.xml
除此之外,它属于我在 web.xml 中设置的 spring 内容,该内容已经过尝试且正确(通过 tomcat)。
main 中的相关代码是这样的(否则它就是属性废话):
svrLogger.info ("Starting server in '" + home + "' on port " + port);
String rsrcBase = "src/main/webapp";
String webXml = rsrcBase + "/WEB-INF/web.xml";
svrLogger.info ("Using resource base: " + rsrcBase);
svrLogger.info ("Using descriptor file: " + webXml);
Server server = new Server(port);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath ("/TestServer");
webapp.setDescriptor (home + "/" + webXml);
webapp.setResourceBase (home + "/" + rsrcBase);
webapp.setParentLoaderPriority (true);
server.setHandler(webapp);
svrLogger.info ("Starting Server!");
server.start();
server.join();
svrLogger.info ("Joined and exiting");
任何帮助都是好的......有帮助的。这是我第一次尝试制作自己的网络服务器(所以也欢迎其他建议!)
I am having some struggles embedding a jetty server into a java app. I am using spring to configure the actual objects and I can build the webapp no problems - but I get this problem when starting up the server...
0 [main] INFO test.Server - Starting server in 'c:/workspace/test/war/' on port 9090
34615 [main] INFO test.Server - Using resource base: src/main/webapp
34615 [main] INFO test.Server - Using descriptor file: src/main/webapp/WEB-INF/web.xml
2011-09-05 12:29:36.961:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
36344 [main] INFO test.Server - Starting Server!
2011-09-05 12:29:37.023:INFO::jetty-6.1H.22
2011-09-05 12:29:37.039:WARN::Failed startup of context org.mortbay.jetty.webapp.WebAppContext@8ab708{/TestServer,file:/C:/workspace/test/war/src/main/webapp/}
java.lang.ClassNotFoundException: org.mortbay.jetty.plus.webapp.EnvConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.mortbay.util.Loader.loadClass(Loader.java:91)
at org.mortbay.util.Loader.loadClass(Loader.java:71)
at org.mortbay.jetty.webapp.WebAppContext.loadConfigurations(WebAppContext.java:859)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:431)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at test.Server.main(Server.java:84)
2011-09-05 12:29:37.054:INFO::Started [email protected]:9090
The problem seems to be with some of my path stuff...the dir structure is straight forward (what maven 'recommends') -
workspace/test/war/
-src/main/java/test/Server.java
-src/main/webapp/WEB-INF/web.xml
Other than that it falls into the spring stuff I have setup in the web.xml that has been tried and true (via tomcat).
The relevant code in main is this (otherwise it is properties crap):
svrLogger.info ("Starting server in '" + home + "' on port " + port);
String rsrcBase = "src/main/webapp";
String webXml = rsrcBase + "/WEB-INF/web.xml";
svrLogger.info ("Using resource base: " + rsrcBase);
svrLogger.info ("Using descriptor file: " + webXml);
Server server = new Server(port);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath ("/TestServer");
webapp.setDescriptor (home + "/" + webXml);
webapp.setResourceBase (home + "/" + rsrcBase);
webapp.setParentLoaderPriority (true);
server.setHandler(webapp);
svrLogger.info ("Starting Server!");
server.start();
server.join();
svrLogger.info ("Joined and exiting");
Any help is well...helpful. This is the first time I have tried to make my own web server (so other advice is welcome too!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Try to include
它正在尝试加载此类,因为 Jetty JNDI 默认情况下未配置。
的更多信息的好资源
这是了解有关 Jetty https://jersey.java.net/documentation /latest/index.html
祝你好运!
Try to include
It's trying to load this class because in Jetty JNDI is not configured by default.
This is a good resource to learn more about Jetty
https://jersey.java.net/documentation/latest/index.html
Good luck!