Explain Codes LogoExplain Codes Logo

How to deploy a war file in Tomcat 7

java
deployment
tomcat
maven
Nikita BarsukovbyNikita BarsukovยทNov 28, 2024
โšกTLDR

To quickly deploy a war file in Tomcat 7, place the war file in the webapps folder, then restart Tomcat. Here are the steps:

  1. Copy the example.war file into webapps:
    # Who needs a GUI when you've got terminal? ๐Ÿ˜Ž
    cp example.war /path/to/tomcat/webapps/
    
  2. 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:

  1. First, ensure the tomcat-users.xml has a user with the manager role.
  2. Launch the Manager at http://localhost:8080/manager/html (replace localhost if needed).
  3. 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.