2010-09-22 79 views
1

我使用Maven和Jetty/Tomcat。我的pom.xml声明我的应用程序的ID为<artifactId>webapp</artifactId>。因此,我的所有webapp源都位于src/main/java/webapp。现在,每当我运行任何Web服务器,我的URL看起来像这样:如何摆脱Java webserver url中的目录前缀?

http://localhost:8080/webapp/index.html 

,我还没有发现一个线索,告诉我如何摆脱应用程序或目录名,使URL看起来像这个:

http://localhost:8080/index.html 

任何提示?

+0

这是 “根上下文”。 – 2010-09-22 11:50:51

回答

1

假设你的意思使用jetty:runtomcat:run mojos(如果没有,请注明你的意思):

在码头,使用contextPath参数:

<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>maven-jetty-plugin</artifactId> 
    <!-- version omitted --> 
    <configuration> 
     <contextPath>/</contextPath> 
     <!-- other config --> 
    </configuration> 
</plugin> 

在Tomcat中它是path参数

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>tomcat-maven-plugin</artifactId> 
    <!-- Version omitted --> 
    <configuration> 
     <path>/</path> 
     <!-- Other configuration --> 
    </configuration> 
</plugin> 
+0

正是我一直在寻找的,谢谢! – 2010-09-22 10:24:19

2

你可以这样做的几种方法:

  • 在Tomcat中,重命名webapp.warROOT.war(注意大小写)
  • 配置Apache最重要的是,创造指向根纠正web应用重写规则。
  • 使用Jetty的contextPath