开发者

Howto get rid of directory prefix in Java webserver url?

开发者 https://www.devze.com 2023-01-16 22:41 出处:网络
I am using Maven with Jetty / Tomcat. My pom.xml declares the ID of my application as <artifactId>webapp</artifactId>. Consequently, all my webapp source is located in src/main/java/webapp

I am using Maven with Jetty / Tomcat. My pom.xml declares the ID of my application as <artifactId>webapp</artifactId>. Consequently, all my webapp source is located in src/main/java/webapp. Now, whenever I run any of the webserver, my URL looks like this:

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

and I haven't found a clue that tells me how to get ri开发者_如何学Pythond of the application or dir name and make the URL look like this:

http://localhost:8080/index.html

Any hints?


Couple of ways you could do this:

  • In Tomcat, rename the webapp.war to ROOT.war (note the capitalization)
  • Configure Apache on top of that and create a rewrite rule for pointing root to correct webapp.
  • Use Jetty's contextPath


Assuming you mean using the jetty:run and tomcat:run mojos (if not, please specify what you mean):

In Jetty, use the contextPath argument:

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

In Tomcat it's the path argument

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

精彩评论

暂无评论...
验证码 换一张
取 消