This is a short post on how to use the root context for your Java web application. This it to make your webapp URL something like http://www.webapp.com instead of http://www.webapp.com/context/. Here we touch on Tomcat, Apache, Jetty and Maven.
1. In Tomcat, edit tomcat/conf/server.xml and change the path attribute of the Context element to “/”.
<?xml version="1.0" encoding="UTF-8"?> <Server ...> ... <Service name="Catalina"> ... <Engine ...> <Host ...> ... <Context path="/" ... /> </Host> </Engine> </Service> </Server>
2. In Apache, if using mod_proxy_http, edit apache/conf/httpd.conf and use ProxyPass / and ProxyPassReverse /.
ProxyPass / http://www.webapp.com:8080/ ProxyPassReverse / http://www.webapp.com:8080/
If mod_jk is used, edit apache/conf/httpd.conf and use JkMount /*.
<VirtualHost *:80> ServerName ... JkMount /* worker1 </VirtualHost>
3. If using Maven, in pom.xml, change configuration/path of plugin/artifactId=tomcat-maven-plugin.
<?xml version="1.0" encoding="UTF-8"?> <project ...> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> ... <configuration> <path>/</path> ... </configuration> </plugin> </plugins> </build> </project>
4. If using Jetty in Maven, continue editing pom.xml. Change the configuration/contextPath of plugin/artifactId=maven-jetty-plugin.
<?xml version="1.0" encoding="UTF-8"?> <project ...> ... <build> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> ... <configuration> <contextPath>/</contextPath> ... </configuration> </plugin> </plugins> </build> </project>