views:

2060

answers:

6
+4  Q: 

Tomcat deployment

Is there a way, given a war file, to deploy on a tomcat server. I want to do this without having to use the web interface.

A: 

you can edit the conf/server.xml and add an entry like this pointing to your war directory

ELSE you can copy your .WAR file to the webapps directory of tomcat.

anjanb
A: 

forgot the entry in the server.xml . here it is

    <Context path="/strutsDisplayTag" 
        reloadable="true" 
        docBase="C:\work\learn\jsp\strutsDisplayTag" 
        workDir="C:\work\learn\jsp\strutsDisplayTag\work" />
anjanb
why don't you just edit your first post?
Nathan Feger
+4  A: 

Just copy the war file into the $TOMCAT_HOME/webapps/ directory. Tomcat will deploy the war file by automatically exploding it. FYI - If you want you can make updates directly to the exploded directory, which is useful for development.

Joe Dean
so, I can run rsync --delete on the directiory on the server?
Milhous
+2  A: 

We never use the web interface, don't like it. The wars are dropped in the webapps and server.xml edited as necessary. You need to bounce it if you edit the server.xml, but the war file should be picked up automagically. We generally delete the directory expanded from the war first so there is no confusion from where the components came.

dacracot
+1  A: 

The Tomcat Client Deployer Package looks to be what you need to deploy to a remote server from the command line. From the page:

This is a package which can be used to validate, compile, compress to .WAR, and deploy web applications to production or development Tomcat servers. It should be noted that this feature uses the Tomcat Manager and as such the target Tomcat server should be running.

John Meagher
+10  A: 

There are several ways to deploy a Tomcat webapp:

  • Dropping into $CATALINA_HOME/webapps, as was already mentioned.
  • Using your build scripts to deploy automatically via the manager interface (that comes with Tomcat). Here are the two ways
    • for Maven: use the tomcat plugin. You don't need to include it in pom.xml, just issue the goal mvn tomcat:deploy, the plugin is included in Maven 2. This assumes several defaults explained in the documentation, you can configure the behaviour in the pom.xml. There are other goals that let you deploy as an exploded archive etc.
    • for Ant: something like this:
    <property name="manager.url"   value="http://localhost:8080/manager"/&gt;
    <property name="manager.username" value="manager"/>
    <property name="manager.password" value="foobar"/>
    <!-- Task definitions -->
    <taskdef name="deploy"   classname="org.apache.catalina.ant.DeployTask"/>
    <taskdef name="list"     classname="org.apache.catalina.ant.ListTask"/>
    <taskdef name="reload"   classname="org.apache.catalina.ant.ReloadTask"/>
    <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
    <!-- goals -->
    <target name="install" depends="compile" description="Install application to servlet container">
     <deploy url="${manager.url}"
       username="${manager.username}"
       password="${manager.password}"
       path="${app.path}"
       localWar="file://${build.home}"/>
    </target>
    <target name="list" description="List installed applications on servlet container">
     <list    url="${manager.url}"
       username="${manager.username}"
       password="${manager.password}"/>
    </target>
    <target name="reload" depends="compile" description="Reload application on servlet container">
     <reload url="${manager.url}"
       username="${manager.username}"
       password="${manager.password}"
       path="${app.path}"/>
    </target>
    <target name="remove" description="Remove application on servlet container">
     <undeploy url="${manager.url}"
       username="${manager.username}"
       password="${manager.password}"
       path="${app.path}"/>
    </target>

All of those will require you to have a Tomcat user configuration. It lives $CATALINA_BASE/conf/tomcat-users.xml, but since you know already how to use the web interface, I assume you know how to configure the users and passwords.

Aleksandar Dimitrov