Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy war on Tomcat without the war name in the URL

I built a war file called myapp.war and deployed it on Tomcat. I've changed the port from 8080 to 80 so I can then get to it at example.com/myapp (where example.com is my host).

How can I get configure the application so that when I go to example.com, it shows my app? I don't want to just redirect from example.com to example.com/myapp - I don't want to have myapp in the URL.
Do I have to set up Apache to serve the pages like this, or can I do it with a virtual host in the Tomcat configuration?

like image 646
George Avatar asked Jan 08 '10 23:01

George


People also ask

How can I deploy WAR file in Tomcat?

Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.

What happens when we deploy a WAR file in Tomcat?

Java web applications are usually packaged as WAR files for deployment. These files can be created on the command line or with an IDE, like Eclipse. After deploying the WAR file, Tomcat unpacks it and stores all the project files from the webapps directory in a new directory named after the project.


Video Answer


2 Answers

All you need to do is name your war ROOT.war.

like image 165
danben Avatar answered Oct 03 '22 12:10

danben


Here are two possible method:

  1. Rename your war to ROOT.war
  2. No need to rename. Go to CATALINA_BASE/conf/server.xml Find Host element and set autoDeploy="false" deployOnStartup="false" then add <Context path="" docBase="your_project_name"/> in the end like:

expamle#2:

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false" deployOnStartup="false"> 

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    <Context path="" docBase="your_project_name"/><!--Add this-->
  </Host>
like image 29
JaskeyLam Avatar answered Oct 03 '22 13:10

JaskeyLam