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?
0
votes
Why do you need an Ant script for this?
- Dave Newton
I once do all of the tasks you list above with bash script. If that's all you're asking for, bash script (or .bat file if you are using windows) is enough
- Hoàng Long
@DaveNewton You can look into it as a constraint - we can only run Ant scripts from the build side.
- user2666282
And why a -1? What was -1 about the question? :)
- user2666282
1 Answers
1
votes
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>