Reputation: 383
We have a Maven project (using Eclipse/Java) that we need to create a war of, and deploy to a remote Tomcat server. We need an ant script for this. Could anyone please share code samples or any other pointers?
Upvotes: 0
Views: 1156
Reputation: 103
You need to create a file like this, I called it build.xml
<project name="APP" default="copywar" basedir=".">
<!--=========================================================================
Helper - Version 0.1
==========================================================================-->
<property name="dist.dir" value="target" />
<property name="tomcat.home" value="YOUR TOMCAT DIR" />
<property name="deploy.dir" value="${tomcat.home}/webapps" />
<property name="website.name" value="APP.war" />
<property name="websitedir.name" value="APP" />
<!-- Undeploys the web site from tomcat -->
<target name="copywar" depends="">
<delete dir="${deploy.dir}/${websitedir.name}" />
<delete file="${deploy.dir}/${website.name}" />
<echo message="Deleted directory and War" />
<!--Copy web application to deplyment dir -->
<copy file="${dist.dir}/${website.name}" todir="${deploy.dir}" />
</target>
And on your pom.xml you need to add
<!-- copyToTomcat with build.xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>package-ear</id>
<phase>package</phase>
<configuration>
<tasks>
<ant target="copywar" inheritRefs="true">
<!-- Here, connect with build.xml -->
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 1