Sometimes it comes in handy to have an ANT target for creating JAR files of your project, e.g. to be able to export it to some other location or project. The following code serves as reference to achieve this behavior. It consists of 6 basic steps:
- call compile target
- delete previous JAR version if it exists
- create JAR file
- create destination folder if it does not yet exist
- copy JAR to destination
- delete local version of JAR
Let’s see some XML
<target name="build-and-copy-to-tomcat-lib"> <antcall target="compile" /> <delete file="${plugin.name}.jar" /> <jar destfile="${plugin.name}.jar" basedir="docroot/WEB-INF/classes"/> <mkdir dir="${app.server.deploy.dir}/../lib/ext/" /> <copy file="${plugin.name}.jar" todir="${app.server.deploy.dir}/../lib/ext/"/> <delete file="${plugin.name}.jar" /> </target>
This example copies the JAR created to your Tomcat’s lib/ext folder so that it is accessible by other applications.