一个完整的JENKINS下的ANT BUILD.XML文件

本文介绍了一个使用Ant构建工具来创建WAR文件的过程。该过程包括清理旧文件、初始化目录、编译Java源代码、构建WAR文件等步骤,并集成了代码风格检查、错误检测及单元测试等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xmlversion="1.0"encoding="UTF-8"?>
<projectname="genwar"default="all"basedir=".">

<description>-Generatewarfile-</description>

<propertyenvironment="env"/>

<propertyname="debuglevel"value="source,lines,vars"/>
<propertyname="target"value="1.6"/>
<propertyname="source"value="1.6"/>

<propertyname="output.dir"location="."/>
<propertyname="output.file"value="new_cos.war"/>

<propertyname="project.build"location="./build"/>
<propertyname="project.src"location="./src"/>
<propertyname="project.web"location="../web"/>
<propertyname="project.lib"location="./lib"/>
<propertyname="project.res"location="./res"/>
<propertyname="project.svc"location="./svc"/>

<propertyname="project.war"location="${project.build}/${output.file}"/>

<propertyname="tmp"location="${project.build}/tmp"/>
<propertyname="tmp.src"location="${tmp}/src"/>
<propertyname="tmp.lib"location="${project.web}/WEB-INF/lib"/>
<propertyname="tmp.bin"location="${tmp}/bin"/>
<propertyname="tmp.web"location="${tmp}/web"/>
<propertyname="tmp.classes"location="${tmp}/classes"/>

<propertyname="checkstyle.dir"location="./ant-task/checkstyle"/>
<propertyname="findbugs.dir"location="./ant-task/findbugs/home"/>
<propertyname="findbugs.report.dir"location="./ant-task/findbugs"/>
<propertyname="junit.reports.dir"value="./ant-task/junit/reports"/>
<propertyname="junit.class.dir"value="./ant-task/junit/bin"/>
<propertyname="junit.test.src"location="./test/java"/>
<propertyname="junit.test.resources"location="./test/resources"/>

<pathid="javaclass.path">
<pathelementpath="${env.classpath}"/>
<pathelementpath="${env.JBOSS_HOME}/server/all/lib/servlet-api.jar"/>
<pathelementpath="${env.JBOSS_HOME}/server/all/lib/jsp-api.jar"/>
<filesetdir="${tmp.lib}"includes="*.jar"/>
<!--<filesetdir="${project.lib}"includes="*.jar"/>-->
</path>

<pathid="findbugs.path">
<filesetdir="${findbugs.dir}"includes="**/*.jar"/>
</path>

<targetname="clean">
<deletefile="${output.dir}/${output.file}"failonerror="false"/>
<deletedir="${project.build}"failonerror="false"/>
<mkdirdir="${project.build}"/>
</target>

<targetname="all"depends="clean,buildwar"/>

<targetname="initdir">

<echomessage="Initdirectories"/>

<deletedir="${tmp}"failonerror="false"/>

<mkdirdir="${tmp}"/>

<mkdirdir="${tmp.src}"/>
<copytodir="${tmp.src}">
<filesetdir="${project.src}"excludes="**/.svn/**"/>
</copy>

<mkdirdir="${tmp.lib}"/>
<!--
<copytodir="${tmp.lib}">
<filesetdir="${project.web}/WEB-INF/lib"includes="*.jar"/>
</copy>
-->


<mkdirdir="${tmp.bin}"/>

<mkdirdir="${tmp.web}/WEB-INF/lib"/>

<deletedir="${tmp.web}/WEB-INF/classes"failonerror="false"/>
<mkdirdir="${tmp.web}/WEB-INF/classes"/>

</target>

<targetname="compilejava"depends="initdir">
<echomessage="Compilingjavacode"/>

<javacdebug="true"debuglevel="${debuglevel}"destdir="${tmp.bin}"source="${source}"target="${target}"encoding="UTF-8">
<srcpath="${tmp.src}"/>
<classpathrefid="javaclass.path"/>
</javac>

<copytodir="${tmp.web}/WEB-INF/classes"includeemptydirs="false">
<filesetdir="${tmp.src}">
<excludename="**/*.java"/>
</fileset>
</copy>
<copytodir="${tmp.web}/WEB-INF/classes"includeemptydirs="false">
<filesetdir="${tmp.bin}">
<includename="**/*.class"/>
</fileset>
</copy>
</target>

<targetname="compilejava-without-copy"depends="initdir">
<echomessage="Compilingjavacode"/>

<javacdebug="true"debuglevel="${debuglevel}"destdir="${tmp.bin}"source="${source}"target="${target}"encoding="UTF-8">
<srcpath="${tmp.src}"/>
<classpathrefid="javaclass.path"/>
</javac>

</target>

<targetname="buildwar"depends="compilejava">

<echomessage="Packingwarfile"/>

<copytodir="${tmp.web}">
<filesetdir="${project.web}"excludes="**/.svn/**"/>
</copy>

<deletefile="${project.war}"failonerror="false"/>
<wardestfile="${project.war}"basedir="${tmp.web}"webxml="${tmp.web}/WEB-INF/web.xml"encoding="utf-8"/>
<deletedir="${tmp}"failonerror="false"/>

<deletefile="${output.dir}/${output.file}"failonerror="false"/>
<movetodir="${output.dir}"includeemptydirs="false"filtering="true">
<filesetdir="${project.build}">
<includename="**/*.war"/>
</fileset>
</move>

<deletedir="${project.build}"failonerror="false"/>

</target>

<taskdefresource="checkstyletask.properties"
classpath
="${checkstyle.dir}/checkstyle-5.5-all.jar"/>

<targetname="checkstyle"
description
="Generatesareportofcodeconventionviolations.">


<checkstyleconfig="${checkstyle.dir}/my_check.xml"
failureProperty
="checkstyle.failure"failOnViolation="false">
<formattertype="xml"tofile="${checkstyle.dir}/checkstyle_report.xml"/>
<filesetdir="${project.src}"includes="**/*.java"/>
</checkstyle>

<!--stylein="checkstyle_report.xml"out="checkstyle_report.html"
style="checkstyle.xsl"/
-->


</target>

<taskdefname="findbugs"classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
classpathref
="findbugs.path"/>


<targetname="findbugs"depends="compilejava-without-copy"
description
="用Findbugs检查代码错误.">
<echo>开始用Findbugs检查代码错误</echo>
<findbugshome="${findbugs.dir}"output="xml"
outputFile
="${findbugs.report.dir}/findbugs_report.xml">
<auxClasspath>
<pathrefid="junit.test.lib.path"/>
</auxClasspath>
<!--auxClasspathpath="${basedir}/lib/Regex.jar"/-->
<sourcePathpath="${tmp.src}"/>
<classlocation="${tmp.bin}"/>
</findbugs>
<echo>Findbugs检查代码错误完成</echo>

<deletedir="${project.build}"failonerror="false"/>
</target>

<targetname="junit-init">
<deletedir="${junit.class.dir}"failonerror="false"/>
<mkdirdir="${junit.class.dir}"/>
<deletedir="${junit.reports.dir}/result-xml"failonerror="false"/>
<mkdirdir="${junit.reports.dir}/result-xml"/>
<deletedir="${junit.reports.dir}/html"failonerror="false"/>
<mkdirdir="${junit.reports.dir}/html"/>
<deletedir="${junit.reports.dir}/html-result"failonerror="false"/>
<mkdirdir="${junit.reports.dir}/html-result"/>
</target>


<targetname="junit-compile"depends="junit-init">
<echomessage="${project.web}/WEB-INF/lib"/>
<javacsrcdir="${project.src}"destdir="${junit.class.dir}"source="${source}"target="${target}"encoding="UTF-8">
<classpathrefid="junit.test.lib.path"/>
</javac>
<javacsrcdir="${junit.test.src}"destdir="${junit.class.dir}"source="${source}"target="${target}"encoding="UTF-8">
<classpathrefid="junit.test.lib.path"/>
</javac>
<copytodir="${junit.class.dir}">
<filesetdir="${junit.test.resources}">
<includename="**/*.xml"/>
</fileset>
</copy>
<copytodir="${junit.class.dir}">
<filesetdir="${project.src}">
<includename="**/*.xml"/>
</fileset>
</copy>
</target>

<pathid="junit.test.lib.path">
<pathelementpath="${env.JBOSS_HOME}/server/all/lib/servlet-api.jar"/>
<pathelementpath="${env.JBOSS_HOME}/server/all/lib/jsp-api.jar"/>
<pathelementpath="${env.JBOSS_HOME}/server/all/lib/jboss-j2ee.jar"/>
<filesetdir="${project.web}/WEB-INF/lib"includes="**/*.jar"/>
<filesetdir="${project.lib}"includes="**/*.jar"/>
</path>


<targetname="junit-test"depends="junit-compile">
<junitprintsummary="yes">
<classpath>
<!--指定lib和class路径,class和jar的声明不能混在一起-->
<pathelementlocation="${junit.class.dir}"/>
<pathrefid="junit.test.lib.path"/>
</classpath>
<batchtesttodir="${junit.reports.dir}/result-xml">
<filesetdir="${junit.test.src}"includes="**/*TestCase.java"/>
<formattertype="xml"/>
</batchtest>
</junit>
<junitreporttodir="${junit.reports.dir}/html-result">
<!--指定测试结果的XML,即上一步产生的XML-->
<filesetdir="${junit.reports.dir}/result-xml">
<includename="TEST-*.xml"/>
</fileset>
<!--根据测试结果XML,生成TESTS-TestSuites.xml,并由此产生HTML文件-->
<reportformat="frames"todir="${junit.reports.dir}/html"/>
<!--
-->

</junitreport>
</target>


</project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值