Automatically deploy web applications to tomcat through ant scripts in Eclipse

1. To use the DeployTask of tomcat, first add the jar where the DeployTask is located to the classpath of ant in the ant environment variable of eclipse

Copy catalina-ant.jar in the lib directory of the tomcat directory to the lib directory of the directory where the eclipse ant plugin is located. Generally, this directory is in a directory beginning with org.apache.ant in the plugins directory of the eclipse directory.

eclipse->window->preference->ant->runtime->classpath, add the jar file copied in the previous step to the classpath

2. Define the tasks of deploy and undeploy in the ant script

<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />

<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

3. Deploy the application in the ant script

<target name="undeploy">

<undeploy url="http://localhost:8080/manager"

username="username"

password="password"

path="/webapp-name" />

</target>

<target name="deploy" depends="cas-war">

<deploy url="http://localhost:8080/manager"

username="username"

password="password"

path="/webapp-name"

update="true"

localWar="${distDir}/webapp-name.war" />

</target>

 

 - Replace username and password with the username/password used to log in to the management interface of tomcat,

 - Replace webapp-name with the name of the application.

 - Execute the deploy task of ant to deploy the war package packaged in ant to tomcat.

In this way, it is not necessary to log in to the tomcat management interface to deploy the application every time after ant is packaged. The same method can be used for the deployment of jboss.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326607736&siteId=291194637