Example Ant Builder J2EE Enterprise Application Archive

Hmm sudah lumayan lama tidak bermain dengan ANT, karena terlalu dimanja dengan Maven. hehe.

Beberapa saat lalu kami memutuskan untuk menggunakan EJB3, JAX-RS dan JAX-WS yang merupakan technology murni bawaan dari J2EE, untuk membuat backend, membuat project kami tidak memerlukan library tambahan yang banyak. Dan sepertinya penggunaan Maven tidak terlalu efektif karena kami hanya menambahkan 5 external library.

Ceritanya 1 hari ini saya agak frustasi, ketika di eclipse untuk build EAR hanya cukup export, ketika saya coba terjemahakan  menggunakan Maven malah  ruwet,  entahlah sepertinya level saya untuk build project EE menggunakan Maven masih perlu belajar lagi, huehue.  Akhirnya saya kangen-kangen sama ANT Builder yang dulu waktu java 1.4, saya sangat berusaha untuk pengen menguasainya. :D

Akhirkata, Alhamdulillah Jenkins saya berjalan dengan baik.

Example :

<project basedir="." default="build" name="gedangambon EJB">

 <available property="jbossdir" value="D:\Source\jboss-eap-6.4\modules" file="D:\Source\jboss-eap-6.4\modules" type="dir" />
 <available property="gedangambonearlib" value="lib" file="lib" type="dir" />

 <!-- Property Declarations-->
 <property name="debuglevel" value="source,lines,vars" />
 <property name="target" value="1.7" />
 <property name="source" value="1.7" />
 <property name="builddir" value="build" />
 <property name="outputartifacts" value="out" />

 <property name="web.name" value="gedangambonws" />
 <property name="web.projectpath" value="D:\Mamat\workspace.gedangambon-bumn\gedangambonws" />
 <property name="web.src" value="${web.projectpath}/src" />
 <property name="web.builddir" value="${builddir}/web" />
 <property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes" />

 <property name="ejb.name" value="gedangambonejb" />
 <property name="ejb.projectpath" value="D:\Mamat\workspace.gedangambon-bumn\gedangambonejb" />
 <property name="ejb.src" value="${ejb.projectpath}/ejbModule" />
 <property name="ejb.builddir" value="${builddir}/ejb" />
 <property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />

 <property name="ear.name" value="gedangambonear" />
 <property name="ear.dir" value="D:\Mamat\workspace.gedangambon-bumn\gedangambonear" />

 <!-- Main Targets -->
 <target name="build" depends="create-ear">
 </target>

 <target name="clean-build">
 <antcall target="clean" />
 <antcall target="build" />
 </target>

 <target name="clean">
 <delete dir="${builddir}" />
 <delete dir="${outputartifacts}" />
 </target>

 <target name="init">
 <mkdir dir="${outputartifacts}" />
 </target>

 <!-- EJB App -->
 <target name="init-ejb" depends="init">
 <mkdir dir="${ejb.builddir}" />
 <copy includeemptydirs="false" todir="${ejb.builddir.classes}">
 <fileset dir="${ejb.src}">
 <exclude name="**/*.java" />
 </fileset>
 </copy>
 </target>
 <target name="build-ejb" depends="init-ejb">
 <javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
 <src path="${ejb.src}" />
 <classpath>
 <fileset dir="${jbossdir}">
 <include name="**/*.jar" />
 </fileset>
 <fileset dir="${outputartifacts}">
 <include name="**/*.jar" />
 </fileset>
 <fileset dir="${gedangambonearlib}">
 <include name="**/*.jar" />
 </fileset>

 </classpath>
 </javac>
 </target>

 <!-- WEB -->
 <target name="init-web" depends="init">
 <mkdir dir="${web.builddir.classes}" />
 <copy includeemptydirs="false" todir="${web.builddir}">
 <fileset dir="${web.projectpath}/WebContent">
 </fileset>
 </copy>
 <copy includeemptydirs="false" todir="${web.builddir.classes}">
 <fileset dir="${web.src}">
 <exclude name="**/*.java" />
 </fileset>
 </copy>
 </target>

 <target depends="init-web" name="build-web">
 <javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
 <src path="${web.src}" />
 <classpath>
 <fileset dir="${glassfishdir}">
 <include name="**/*.jar" />
 </fileset>
 <fileset dir="out/">
 <include name="**/*.jar" />
 </fileset>
 <fileset dir="${gedangambonearlib}">
 <include name="**/*.jar" />
 </fileset>
 </classpath>
 </javac>
 </target>

 <!-- CREATE ARCHIVES -->
 <target name="create-web" depends="build-web">
 <war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml" />
 </target>

 <target name="create-ejb" depends="build-ejb">
 <jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
 <manifest>
 <attribute name="Class-Path" value="${ejbclient.name}.jar" />
 </manifest>
 </jar>
 </target>

 <target name="create-ear" depends="create-web,create-ejb">
 <ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/META-INF/application.xml">
 <zipfileset dir="${ear.dir}/lib" prefix="lib">
 <include name="*.jar" />
 </zipfileset>
 <fileset dir="${outputartifacts}" includes="*.jar,*.war" />
 </ear>
 </target>
</project>

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>