2011-03-16 55 views
1

工作,我有以下代码:嵌入式应用码头不是从罐子

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.domainMain类。

jsp和html位于com.domain.webapps.app包中。

在Netbeans内部运行(或爆炸式jar中的java -cp <classpath> com.domain.Main)时,应用程序可以正常工作。

如果我运行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的请求,码头尝试从/tmp/Jetty_something/webapp/file.jsp文件(错了地方:-()

我能做些什么,在哪里?

码头的版本是6.1.26

回答

0

看一看this文章。网址是由

ProtectionDomain protectionDomain = Start.class.getProtectionDomain(); 
URL location = protectionDomain.getCodeSource().getLocation(); 

检测这对我的作品在war项目,也许还为您jar使用情况。