How to deploy a war file in Tomcat 7
To quickly deploy a war file in Tomcat 7, place the war file in the webapps folder, then restart Tomcat. Here are the steps:
- Copy the
example.warfile intowebapps:# Who needs a GUI when you've got terminal? π cp example.war /path/to/tomcat/webapps/ - Restart Tomcat for the magic to happen.
Now, open your browser to http://yourserver:8080/example to see your live application. Achieve real-time deployment by enabling autoDeploy in the server.xml:
<Host appBase="webapps" autoDeploy="true">
...
</Host>
Stumbled upon issues? Check logs at tomcat/logs/catalina.out.
Detailed deployment guidelines
Sometimes, you may need more deployment control, either remotely or through a GUI. This is where the Tomcat Manager app steps in!
The Tomcat Manager suite
Deploy a war file using the Tomcat Manager:
- First, ensure the
tomcat-users.xmlhas a user with themanagerrole. - Launch the Manager at
http://localhost:8080/manager/html(replacelocalhostif needed). - Upload the war file and click Deploy.
Your app will appear in the Applications section upon successful deployment.
Server adjustments
If your server doesn't use the default HTTP port (8080), check the server.xml for the appropriate settings under the Connector tag.
For customized deployment settings, inspect the <Host> tag in server.xml for useful attributes like autoDeploy and deployOnStartup.
Solutions to common issues
In case of deployment hurdles, here's your rescue kit:
- After moving the war file, ensure a corresponding folder exists in
webapps. - Look through the Tomcat logs for any startup errors or Java exceptions.
- Double-check if the app's context path is correct in your URL.
Advanced deployment techniques
Along with manual and Tomcat Manager methods, you also have options like Maven or IDE integrations.
Maven-powered deployments
With the tomcat7-maven-plugin, direct deployments are a breeze:
# Maven - more dependable than my last relationship π
mvn tomcat7:deploy
IDE integrations
IDEs like IntelliJ IDEA and Eclipse offer built-in Tomcat support, allowing you to deploy and manage apps right from the IDE.
Was this article helpful?