views:

34

answers:

2

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 rid of the application or dir name and make the URL look like this:

http://localhost:8080/index.html

Any hints?

+1  A: 

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>
seanizer
Precisely what I had been looking for, thanks!
+2  A: 

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
Esko