嵌入式码头应用程序无法从 jar 运行
我有以下代码:
Server server = new Server(9090);
final URL warUrl = Main.class.getClassLoader().getResource("com/domain/webapps/app");
final String warUrlString = warUrl.toExternalForm();
WebAppContext wac = new WebAppContext(warUrlString, "/app");
server.setHandler(wac);
我在 com.domain
包中有 Main
类。
jsp 和 html 位于 com.domain.webapps.app
包中。
当在 Netbeans 内运行(或在分解的 jar 上运行 java -cp
如果我运行 jar (java -jar app.jar
),com.domain.webapps.app
的内容将被提取到 /tmp/Jetty_something/ webapp/
,所以完整路径是 /tmp/Jetty_something/webapp/com/domain/webapps/app/
但是当我向 http://localhost 发出请求时: 9090/app/file.jsp
,Jetty 尝试从 /tmp/Jetty_something/webapp/file.jsp
获取文件(错误的位置:-( )
我能在哪里做什么?
Jetty版本是6.1.26
I have the following code:
Server server = new Server(9090);
final URL warUrl = Main.class.getClassLoader().getResource("com/domain/webapps/app");
final String warUrlString = warUrl.toExternalForm();
WebAppContext wac = new WebAppContext(warUrlString, "/app");
server.setHandler(wac);
I have the Main
class in the com.domain
package.
The jsp's and html's are in the com.domain.webapps.app
package.
When run inside Netbeans (or java -cp <classpath> com.domain.Main
on the exploded jar) the application works perfectly.
If i run the jar (java -jar app.jar
), the content of the com.domain.webapps.app
gets extracted to /tmp/Jetty_something/webapp/
, so the full path is /tmp/Jetty_something/webapp/com/domain/webapps/app/
But when i make a request for http://localhost:9090/app/file.jsp
, Jetty tries to get the file from /tmp/Jetty_something/webapp/file.jsp
(the wrong place :-( )
What can i do where ?
Jetty version is 6.1.26
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看这篇文章。 URL 是由
这对我的
war
项目有用,也许也适用于您的jar
用例。Have a look at this article. The URL is detected by
This works for me in a
war
project and maybe also for yourjar
use case.