Wednesday, December 16, 2009

Ant Script to compile,deploy,test EJB Appication

<project name="jblog" default="ear">

<property environment="env"/>

<property name="jboss.home" value="${env.JBOSS_HOME}"/>

<property name="jboss.server.dir" value="${jboss.home}/server/default"/>

<property name="jboss.deploy.dir" value="${jboss.server.dir}/deploy"/>

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

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

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

<property name="docs.test.dir" value="${docs.dir}/test"/>

<property name="docs.api.dir" value="${docs.dir}/api"/>

<property name="app.ear" value="${ant.project.name}.ear"/>

<property name="app.war" value="${ant.project.name}.war"/>

<property name="app.ejb.jar" value="${ant.project.name}-ejb.jar"/>

<property name="app.client.jar" value="${ant.project.name}-client.jar"/>

<property name="app.test.jar" value="${ant.project.name}-test.jar"/>

<property name="test.args" value=""/>

<property name="test.include" value="**/*Test.class"/>

<property name="test.exclude" value=""/>

<property name="db.url" value="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1111:sid"/>

<property name="db.user" value="ehosbk"/>

<property name="db.password" value="ehosbk"/>

<property name="db.driver" value="oracle.jdbc.driver.OracleDriver"/>



<!-- compile classpath -->

<path id="compile.class.path">

<pathelement location="${env.J2EE_HOME}/lib/j2ee.jar"/>

<pathelement location="${env.JUNIT_HOME}/junit-4.4.jar"/>

</path>



<!-- test classpath -->

<path id="test.class.path">

<pathelement location="."/>

<pathelement location="${app.test.jar}"/>

<pathelement location="${app.client.jar}"/>

<pathelement location="${jboss.home}/client/jbossall-client.jar"/>

<pathelement location="${jboss.home}/server/default/lib/classes12.jar"/>

<path refid="compile.class.path"/>

</path>



<!-- all -->

<target name="all" depends="clean,ear,deploy,test"/>



<!-- compile -->

<target name="compile">

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



<javac srcdir="${source.dir}" destdir="${classes.dir}"

classpathref="compile.class.path" debug="yes"/>



<copy todir="${classes.dir}">

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

<include name="META-INF/**"/>

</fileset>

</copy>

</target>



<!-- jar -->

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

<jar jarfile="${app.ejb.jar}">

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

<include name="META-INF/ejb-jar.xml"/>

<include name="META-INF/jboss.xml"/>

<include name="META-INF/jbosscmp-jdbc.xml"/>

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

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

</fileset>

</jar>

<jar jarfile="${app.client.jar}">

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

<include name="**/Author.class"/>

<include name="**/Story.class"/>

<include name="**/Blog.class"/>

<include name="**/*Home.class"/>

</fileset>

</jar>

<jar jarfile="${app.test.jar}">

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

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

</fileset>

</jar>

</target>



<!-- war -->

<target name="war">

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

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

<include name="WEB-INF/web.xml"/>

<include name="*.jsp"/>

</fileset>

</jar>

</target>



<!-- ear -->

<target name="ear" depends="jar,war">

<jar jarfile="${app.ear}">

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

<include name="META-INF/application.xml"/>

<include name="${app.ejb.jar}"/>

</fileset>

<fileset dir=".">

<include name="${app.ejb.jar}"/>

<include name="${app.war}"/>

</fileset>

</jar>

</target>



<!-- deploy -->

<target name="deploy">

<copy file="${app.ear}" todir="${jboss.deploy.dir}"/>

</target>



<!-- undeploy -->

<target name="undeploy">

<delete file="${jboss.deploy.dir}/${app.ear}" quiet="true"/>

</target>



<!-- test -->

<target name="test">

<!-- Make docs. dir. -->

<mkdir dir="${docs.test.dir}"/>



<!-- Run test. -->

<junit fork="true" printsummary="on" showoutput="true"

failureproperty="test.failures" errorproperty="test.errors">

<sysproperty key="db.url" value="${db.url}"/>

<sysproperty key="db.user" value="${db.user}"/>

<sysproperty key="db.password" value="${db.password}"/>

<sysproperty key="db.driver" value="${db.driver}"/>



<jvmarg line="${test.args}"/>



<classpath refid="test.class.path"/>



<formatter type="xml"/>



<batchtest todir="${docs.test.dir}">

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

<include name="${test.include}"/>

<exclude name="${test.exclude}"/>

</fileset>

</batchtest>

</junit>



<!-- Run report. -->

<junitreport todir="${docs.test.dir}">

<fileset dir="${docs.test.dir}">

<include name="TEST-*.xml"/>

</fileset>

<report format="frames" todir="${docs.test.dir}"/>

</junitreport>



<!-- Fail if failures or errors. -->

<fail if="test.failures">Test failures.</fail>

<fail if="test.errors">Test errors.</fail>

</target>



<!-- clean -->

<target name="clean">

<delete includeEmptyDirs="true" quiet="true">

<fileset dir=".">

<include name="*.jar"/>

<include name="*.war"/>

<include name="*.ear"/>

<include name="junit*.properties"/>

</fileset>

<fileset dir="${classes.dir}"/>

<fileset dir="${docs.dir}"/>

</delete>

</target>

</project>

No comments: