2010-09-22 81 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