License Public Domain
Lines 79
Keywords
ant (2) build (2) j2ee (3)
Permissions
Owner: jlugocp
Viewable by Everyone
Editable by jlugocp's Friends
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

Basic Ant script for J2EE project Atom Feed 2

In Brief Not perfect, but it will compile and create a WAR file.
# 's
 1<?xml version="1.0" encoding="UTF-8"?>
2
3<project name="activator" basedir="." default="deploy">
4
5 <property file="build.properties" />
6
7 <property name="build.dir" value="build" />
8
9 <property name="lib.dir" value="lib" />
10
11 <property name="src.dir" value="src" />
12
13 <property name="web.dir" value="WebContent" />
14
15 <property name="test.dir" value="test" />
16
17 <property name="test.build.dir" value="${build.dir}/test" />
18
19 <property name="deploy.dir" value="C:/apache-tomcat-6.0.18/webapps" />
20
21 <path id="classpath.build">
22 <fileset dir="${lib.dir}">
23 <include name="*.jar" />
24 </fileset>
25 <fileset dir="C:\Sun\SDK\lib">
26 <include name="javaee.jar" />
27 </fileset>
28 </path>
29
30 <target name="init">
31 <delete>
32 <fileset dir="${build.dir}" includes="**/*"/>
33 </delete>
34 <mkdir dir="${build.dir}" />
35 <mkdir dir="${build.dir}/classes" />
36 <mkdir dir="${build.dir}/WEB-INF/lib" />
37 <mkdir dir="${build.dir}/WEB-INF/classes" />
38 </target>
39
40 <target name="compile" depends="init">
41 <javac srcdir="${src.dir}" destdir="${build.dir}/WEB-INF/classes" fork="yes" classpathref="classpath.build" />
42 </target>
43
44 <target name="deploy" depends="war,jar" description="Generates the ear file and deploys to deploy directory">
45 <copy todir="${deploy.dir}" file="${build.dir}/${ant.project.name}.war" overwrite="true" />
46 </target>
47
48 <target name="war" depends="pre-war">
49 <war destfile="${build.dir}/${ant.project.name}.war" webxml="${build.dir}/WEB-INF/web.xml">
50 <fileset dir="${build.dir}">
51 <include name="WEB-INF/**" />
52 </fileset>
53 <fileset dir="${web.dir}">
54 <include name="**/css/**/*.css" />
55 <include name="**/*.js" />
56 <include name="**/images/**/*" />
57 <include name="**/*.html" />
58 <include name="**/*.jsp" />
59 <include name="**/*.gif" />
60 </fileset>
61 </war>
62 </target>
63
64 <!-- BUILD THE JAR FILE -->
65 <target name="jar" depends="init,compile">
66 <jar destfile="${build.dir}/${ant.project.name}.jar">
67 <fileset dir="${build.dir}/classes/" />
68 <fileset dir="${lib.dir}">
69 <include name="**/*.jar" />
70 </fileset>
71 <fileset dir="${web.dir}">
72 <include name="META-INF/**" />
73 </fileset>
74 </jar>
75 </target>
76 <target name="pre-war" depends="compile">
77 <copy todir="${build.dir}/WEB-INF/lib">
78 <fileset dir="${lib.dir}">
79 <include name="**/*" />
80 </fileset>
81 </copy>
82 <copy todir="${build.dir}/WEB-INF">
83 <fileset dir="${web.dir}/WEB-INF">
84 <include name="**/*" />
85 </fileset>
86 </copy>
87 </target>
88
89</project>

Not perfect, but it will compile and create a WAR file.

Comments

over 9 years ago (29 Sep 2008 at 11:26 PM) by Stou S.
Very nice, since I never got around the learning ant this should serve me well =)
over 8 years ago (01 Apr 2009 at 09:19 PM) by Andrew Stromberg
Thanks for putting this together, I just started messing with Tomcat and this helped me a bunch.