HOME | SITEMAP
Build War menggunakan Ant
Posted on 2011-11-25 00:52:18 by mamat, 0 Comments
Build War dengan menggunakan Ant sangat dinamis, contoh pada kasus yang saya punya adalah dimana enviroment development kita akan secara otomatis melakukan build war dan langsung mendeploy web server(*kasus ini web server menggunakan tomcat).
Karena kita melakukan development menggunakan Eclipse, awalnya sangat susah jika melakukan Build War pada ant default. Akhirnya dengan mencotek configurasi dari Eclipse builder dan menambahkan lib Eclipse ke server, bisa jalan build War secara smooth. Alhamdulillah... hehe.
Agar build war dan deployment bisa dilakukan secara otomatis, command pada ant ditanam pada conjob diserver. Berikut ini command ant dengan script yang sudah saya buat:
Clean Class - ini akan membersihkan compailer yang lama (*.class)
ant clean
Create War - membuat War
ant create
Deploy War - untuk melakukan deploy ke web server(*tomcat), untuk web server configurasi autodeploy jika ada file baru yang masuk.
ant deploy
Berikut ini adalah detil script ant yang sudah dibuat:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="WebAppTest">
<property environment="env" />
<property name="ECLIPSE_HOME" value="/opt/eclipselib" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.5" />
<property name="source" value="1.5" />
<property name="warfile" value="WebAppTest" />
<path id="J2EE 1.4 Library Container.libraryclasspath">
<pathelement location="/opt/eclipselib/1.4/activation.jar" />
<pathelement location="/opt/eclipselib/1.4/javax.servlet.jar" />
<pathelement
location="/opt/eclipselib/1.4/javax.servlet.jsp.jar" />
<pathelement location="/opt/eclipselib/1.4/jboss-j2ee.jar" />
<pathelement location="/opt/eclipselib/1.4/jboss-jaxrpc.jar" />
<pathelement location="/opt/eclipselib/1.4/jboss-jsr77.jar" />
<pathelement location="/opt/eclipselib/1.4/jboss-saaj.jar" />
<pathelement location="/opt/eclipselib/1.4/mail.jar" />
<pathelement location="/opt/eclipselib/1.4/namespace.jar" />
<pathelement location="/opt/eclipselib/1.4/xml-apis.jar" />
</path>
<path id="WebAppTest.classpath">
<pathelement location="WebRoot/WEB-INF/classes" />
<path refid="J2EE 1.4 Library Container.libraryclasspath" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-collections-2.1.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-fileupload.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-lang-2.0.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-logging-1.0.2.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-net-1.4.1.jar" />
<pathelement location="WebRoot/WEB-INF/lib/cos.jar" />
<pathelement location="WebRoot/WEB-INF/lib/itext-1.1.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/jakarta-oro-2.0.8.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/jasperreports-3.0.0.jar" />
<pathelement location="WebRoot/WEB-INF/lib/jodd.jar" />
<pathelement location="WebRoot/WEB-INF/lib/log4j-1.2.8.jar" />
<pathelement location="WebRoot/WEB-INF/lib/mail.jar" />
<pathelement location="WebRoot/WEB-INF/lib/oracle.jar" />
<pathelement location="WebRoot/WEB-INF/lib/poi-2.5.1.jar" />
<pathelement location="WebRoot/WEB-INF/lib/smart.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-fileupload-1.2.1-javadoc.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-fileupload-1.2.1-sources.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-fileupload-1.2.1.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-io-1.3.2.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-lang-2.3.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-logging-1.0.4.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-pool-1.3.jar" />
<pathelement
location="WebRoot/WEB-INF/lib/commons-validator-1.3.0.jar" />
<pathelement location="WebRoot/WEB-INF/lib/activation.jar" />
</path>
<target name="init">
<mkdir dir="WebRoot/WEB-INF/classes" />
<copy includeemptydirs="false"
todir="WebRoot/WEB-INF/classes">
<fileset dir="src" excludes="**/*.launch, **/*.java" />
</copy>
</target>
<target name="clean">
<delete dir="WebRoot/WEB-INF/classes" />
</target>
<target depends="clean" name="cleanall" />
<target depends="build-subprojects,build-project" name="build" />
<target name="build-subprojects" />
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}"
destdir="WebRoot/WEB-INF/classes" source="${source}"
target="${target}">
<src path="src" />
<classpath refid="WebAppTest.classpath" />
</javac>
</target>
<target
description="Build all projects which reference this project. Useful to propagate changes."
name="build-refprojects" />
<target
description="copy Eclipse compiler jars to ant lib directory"
name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins"
includes="org.eclipse.jdt.core_*.jar" />
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar" />
<fileset dir="${ECLIPSE_HOME}/plugins"
includes="org.eclipse.jdt.core_*.jar" />
</unzip>
</target>
<target description="compile project with Eclipse compiler"
name="build-eclipse-compiler">
<property name="build.compiler"
value="org.eclipse.jdt.core.JDTCompilerAdapter" />
<antcall target="build" />
</target>
<target name="create">
<war destfile="${warfile}.war" webxml="WebRoot/WEB-INF/web.xml"
update="true">
<classes dir="build/classes" />
<fileset dir="WebRoot">
<exclude name="WEB-INF/web.xml" />
</fileset>
</war>
</target>
<target name="copy">
<copy todir="/opt/apache-tomcat-6.0.29/webapps" overwrite="true">
<fileset dir=".">
<include name="*.war" />
</fileset>
</copy>
</target>
<target name="deploy">
<antcall target="create"/>
<antcall target="copy"/>
</target>
</project>
Other Articles
- Build War menggunakan Ant mamat, 2011-11-25 00:52:18
- Eclipse - Tomcat There are no resources that can be added or removed from the server mamat, 2011-11-24 11:59:13
- Contoh Code sederhana untuk Test JNDI DataSource mamat, 2011-04-07 13:44:13
- Reading from and Writing to a URLConnection mamat, 2010-06-08 17:27:55
- Membangun Service Oriented Architecture(SOA) dg EJB, Web Services, Hibernate, Spring dan Mysql (2) mamat, 2010-01-19 17:09:59
- Membangun Service Oriented Architecture(SOA) dg EJB, Web Services, Hibernate JPA, Spring dan Mysql (1) mamat, 2010-01-19 02:18:02
- Membuat Dokumentasi Class menggunakan Javadoc Tool. mamat, 2009-10-28 10:39:09
- Tutorial Spring, Hibernate dan Mysql CRUD(2) mamat, 2009-10-23 00:11:27
- J2ME HTTP Connection Send Text and Send Image then catch using Servlet(2) mamat, 2009-08-10 17:23:19
- One Manga Downloader using Java dan Linux. mamat, 2009-03-20 20:02:22
- J2ME HTTP Connection Send Text and Send Image then catch using Servlet(1) mamat, 2009-01-21 04:49:00
- Tutorial Spring, Hibernate dan Mysql CRUD(1) mamat, 2009-01-14 17:20:38
- Web Service Security mamat, 2008-12-24 18:13:18
- HttpConnection Untuk Load String dan Image mamat, 2008-09-05 16:04:19
- Bedah Code Mobile Kamus mamat, 2008-08-25 17:06:09
- Mobile Kamus mamat, 2008-08-19 15:31:49
- Contoh Source Code JAVA buat Kirim Email(JavaMail API) mamat, 2008-07-21 15:17:22
- Report with Jasper Report in SERVELET mamat, 2008-06-30 11:22:28
- JSP dan Servelet vs SQL2Java mamat, 2008-06-30 10:13:59
- SQL2Java Jadul tapi cepat mamat, 2008-06-20 11:50:58
- Example Source Code using RMS in J2ME mamat, 2008-05-27 13:57:07
- Simultan Load Image in JAVA mamat, 2008-05-01 10:40:34
- Contoh Source Code EJB vs Entity Databse Derby mamat, 2008-04-08 11:11:31
- Play Wav in Java (Streaming jug bisa) mamat, 2008-03-31 14:35:27
- Create Icon Frame in Java(Bikin Icon di Frame Java) mamat, 2008-03-12 10:11:15
- "GPSylon" Framework buat Tracking GPS di JAVA mamat, 2008-02-19 13:55:04
- Bikin Extreme GUI di Java mamat, 2008-02-03 22:13:20
- Mengubah ICON pada JTree di JAVA mamat, 2007-11-14 11:44:13
- Bikin Annotations di Java mamat, 2007-11-12 09:27:10
- Targeting GPS - Integrating J2ME, GPS, and the Wireless Web mamat, 2007-11-02 10:40:56
- Understanding Spring Packaging mamat, 2007-10-05 14:59:34
- SPRING FRAMEWORK mamat, 2007-09-19 13:16:57
- Free Hosting JAVA Server(myjavaserver.com) mamat, 2007-08-14 12:53:22
- JavaFX (Imagine the Possibilities) mamat, 2007-07-19 13:08:50
- Capture Image and send on Server(J2ME) mamat, 2007-07-17 00:00:00

