ant

Ant script for Java project build

gregorio 2018. 7. 5. 13:51

일반적인 Java project를 빌드하여 개발환경에 배포하는 Ant Script이다.


■ Ant script 예제

<?xml version="1.0" encoding="UTF-8"?>


<project name="portal" default="default" basedir=".">


    <!-- CI Informaton for build   -->

    <property name="ci.home"           value="/engn001/ciserv" />

<property name="ci.job.home"       value="${ci.home}/hudson/jobs" />

<property name="ci.app.home"       value="${ci.job.home}/HUDSON-JOB-NAME/workspace" />


<-- Project informamtion -->

    <property name="app.name" value="xxxx" />

    <property name="java.encoding" value="UTF-8" />

<property name="src.dir"  value="src/main/java" />


    <!-- Copy source to tempoary directory -->

<property name="tmp.dir" value="${ci.app.home}/target/${app.name}"/>

    <property name="tmp.dir.classes" value="${tmp.dir}/WEB-INF/classes"/>


    <property name="lib.dir" value="${tmp.dir}/WEB-INF/lib"/>

<!-- Server information for development -->

<property name="was.ip" value=""/>

<property name="was.port" value="" /> 

<property name="was.userid" value="" />

<property name="keyfile.dir" value="" />

<property name="was.home" value="/engn001/apache-tomcat-7.0.76" />

<property name="ci.war.dir" value="/engn001/ciserv/hudson/jobs/HUDSON-JOB-NAME/workspace" />

<property name="war.filename" value="portal.war" />

<!-- Source directory for development -->

<property name="was.tmp.src.dir" value="" /> 

<property name="was.src.dir" value="" />


<!-- =============================================================== -->

<!-- Build source to war  -->

<!-- =============================================================== -->

<path id="classpath">

<fileset dir="${lib.dir}" includes="**/*.jar"/>

<fileset dir="/engn001/ciserv/lib/tomcat7" includes="**/*.jar"/>

</path>


<!-- Start Build -->

    <target name="default" depends="init, prepare, compile, war, stop-tomcat, copy-war, unzip-war, start-tomcat"/>

<!-- Tempoary directory delete and create -->

    <target name="init">

    <delete dir="${tmp.dir.classes}"/>

    <mkdir  dir="${tmp.dir}" />

    <mkdir  dir="${tmp.dir.classes}" />

    </target>


<!-- Synchronize source to tempoary directory -->

    <target name="prepare" depends="init">

    <sync todir="${tmp.dir}">

<fileset dir="${src.dir.web}"/>

</sync>

    <sync todir="${tmp.dir.classes}">

<fileset dir="${src.resources.dir}"/>

</sync>


    </target>


<!-- Source compile for portal development -->

    <target name="compile" depends="prepare">

    <javac srcdir="${src.dir}" destdir="${tmp.dir.classes}" deprecation="off" debug="on" includeantruntime="true">

<classpath refid="classpath"/>

</javac>

</target>


<!-- Generate war file for portal development -->

    <target name="war" depends="compile">

<jar jarfile="${app.name}.war">

<fileset dir="${tmp.dir}">

<include name="**/*"/>

<exclude name="demo/**"/>

<exclude name="help/**"/>

<exclude name="report/**"/>

<exclude name="resource/**"/>

<exclude name="xml/**" />

</fileset>

</jar>

</target>

    <!-- Copy war file to portal development server in /tmp/src directory-->

<target name="copy-war" depends="war">

<echo message="Remote copy war file to was server "/>

<exec executable="scp" dir="." failonerror="true">

    <arg value="-r"/>

    <arg value="-i"/>

    <arg value="${keyfile.dir}" />

    <arg value="${ci.war.dir}/${war.filename}" />

    <arg value="${was.userid}@${was.ip}:${was.tmp.src.dir}"/>

    </exec>

</target>

<!--Stop tomcat -->

<target name="stop-tomcat" depends="copy-war">

<sshexec  host="${was.ip}"

username="${was.userid}"

port="${was.port}"

keyfile="${keyfile.dir}"

command="sudo su -c ${was.home}/bin/shutdown.sh tomcat;

cd ${was.src.dir};

sudo rm -rf *"

trust="true"/>

</target>

<sleep seconds="10" />

<!-- Unzip war file in portal development source directory -->

<target name="unzip-war" depends="stop-tomcat">

<echo message="WAS server source unzip" />

<sshexec  host="${was.ip}"

username="${was.userid}"

keyfile="${keyfile.dir}"

port="${was.port}"

command="sudo cp ${was.tmp.src.dir}/${war.filename} ${was.src.dir};

cd ${was.src.dir};

sudo unzip ${was.src.dir}/${war.filename};

sudo cp ${was.src.dir}/WEB-INF/classes/svrcfg/dev/bizactor.controlling.jar ${was.src.dir}/WEB-INF/lib/bizactor.controlling.jar;

sudo cp ${was.src.dir}/WEB-INF/classes/svrcfg/dev/bizactor.modeling.jar ${was.src.dir}/WEB-INF/lib/bizactor.modeling.jar;

sudo rm -rf ${was.src.dir}/${app.name}.war;

sudo chown -R tomcat:tomcat /logs001/ibm;

sudo chown -R tomcat:tomcat *"

trust="true"/>

<echo message="Web server source unzip" />

</target>

<!-- Start portal development tomcat -->

<echo message="Tomcat Start" />

<target name="start-tomcat" depends="unzip-war">

<sshexec  host="${was.ip}"

username="${was.userid}"

keyfile="${keyfile.dir}"

port="${was.port}"

command="cd ${was.src.dir}

sudo chown -R tomcat:tomcat *;

sudo su -c ${was.home}/bin/startup.sh tomcat"

trust="true"/>

</target>

</project>