关闭

Ant文件build.xml

523人阅读 评论(0) 收藏 举报
<?xml version="1.0" encoding="utf-8"?>
<project name="JpaOneToMany" basedir=".">
   <property environment="env" />
   <property name="project.root" value="." />
   <property name="build.dir" value="${basedir}/build" /> 
   <property name="src.dir" value="${basedir}/src" /> 
   <property name="dist" value="${project.root}/dist" />
   
   <path id="classpath">
     <fileset dir="${project.root}/lib">
       <include name="*.jar" />
     </fileset>
   </path>
	
   <target name="classes-clean" description="清空classes所在目录bin">
      <delete dir="${project.root}/bin" />
   </target>
   
   <target name="create-bin" description="构建clases文件目录bin">
      <mkdir dir="${project.root}/bin" />
   </target>
   
   <target name="compile"  depends="create-bin" description="编译java源文件">
     <copy todir="${project.root}/bin">
	<fileset dir="${src.dir}" includes="**/*.xml" />
	<fileset dir="${src.dir}" includes="**/*.properties" />
    </copy>
		
     <javac srcdir="${src.dir}" includes="**" excludes="**/applet/**" encoding="utf-8" destdir="${project.root}/bin"  source="1.6"     target="1.6" nowarn="true" debug="true" debuglevel="lines,vars,source">
   <classpath refid="classpath" />
    </javac>
</target>
	
   <target name="jar" depends="compile" description="打包java源文件">
		<delete dir="${dist}" />
		<mkdir dir="${dist}" />
		<jar destfile="${dist}/${ant.project.name}.jar">
			<!--<manifest>
				<attribute name="Built-By" value="${user.name}" />
				<attribute name="Specification-Version" value="${project.version}" />
			</manifest>
			-->
			<fileset dir="${project.root}/bin">
			</fileset>
			<fileset dir="${project.root}/lib">
				<!--<exclude name="**/jsp-api.jar" />
				<exclude name="**/cfg.properties" />
				<exclude name="**/log4j.properties" />
			   -->
			</fileset>
		</jar>
	</target>
</project>


项目中的build.xml文件模板:

<?xml version="1.0" encoding="utf-8"?>
<project name="SF_DP" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
	<!-- =================================================================== -->
	<!-- 变量设置 -->
	<!-- =================================================================== -->
	<property environment="env" />
	<property name="project.root" value="." />
	<!-- 代码目录 -->
	<property name="java" value="${project.root}/src/main/java" />
	<property name="javatest" value="${project.root}/src/test" />
	<property name="res" value="${project.root}/src/main/resource" />
	<property name="web" value="${project.root}/src/main/webapp" />
	<property name="webinf" value="${project.root}/src/main/webapp/WEB-INF" />
	<property name="lib" value="${webinf}/lib" />
	<property name="bin" value="${webinf}/classes" />
	<property name="dist" value="${project.root}/dist" />
	<property name="report" value="${project.root}/report" />
	<property name="test-reports" value="${project.root}/test-reports" />
	<property name="container" value="${container.home}" />
	<property name="ivycache" value="${user.home}/.ivy2" />

	<property file="build.properties" />

	<target name="classes-clean" description="清空classes目录">
		<delete dir="${bin}" />
	</target>

	<target name="lib-clean" description="清空jar及ivy缓存">
		<!--<delete dir="${ivycache}" />-->
		<delete dir="${lib}" />
	</target>

	<target name="clean" depends="classes-clean,lib-clean" description="清空所有构建文件">
		<delete dir="${report}" />
	</target>

	<target name="configure-lib" unless="ivy-already-configured" description="设置第三方包配置文件">
		<ivy:configure url="${ivysettings.url}" />
		<ivy:cleancache />
		<property name="ivy-already-configured" value="true" />
	</target>

	<target name="get-lib" depends="configure-lib" description="下载或从本地缓存获取第三方包">
		<ivy:resolve file="ivy.xml" conf="*" />
		<ivy:retrieve pattern="${lib}/[artifact].[ext]" />
		<ivy:resolve file="src/main/webapp/sf_home/sf-ivy.xml" conf="*" />
		<ivy:retrieve pattern="${lib}/[artifact].[ext]" />
	</target>

	<path id="classpath">
		<fileset dir="${lib}">
			<include name="*.jar" />
		</fileset>
		<pathelement path="${bin}" />
	</path>
	<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
	<target name="compile" depends="get-lib" description="Compile java source">
		<copy todir="${bin}">
			<fileset dir="${res}" includes="**" />
		</copy>
		<javac srcdir="${java}" includes="**" excludes="**/applet/**" encoding="utf-8" destdir="${bin}" source="1.6" target="1.6" nowarn="true" debug="true" debuglevel="lines,vars,source" compiler="${build.compiler}">
			<classpath refid="classpath" />
		</javac>
		<copy todir="${bin}">
			<fileset dir="${java}" includes="**/*.xml" />
		</copy>
	</target>
	<target name="junit-compile" depends="get-lib" description="Compile java source">
		<copy todir="${bin}">
			<fileset dir="${res}" includes="**" />
		</copy>
		<javac srcdir="${java}" includes="**" excludes="**/applet/**" encoding="utf-8" destdir="${bin}" source="1.6" target="1.6" nowarn="true" debug="true" debuglevel="lines,vars,source" compiler="${build.compiler}">
			<classpath refid="classpath" />
		</javac>
		<javac srcdir="${javatest}" includes="**" excludes="**/applet/**" encoding="utf-8" destdir="${bin}" source="1.6" target="1.6" nowarn="true" debug="true" debuglevel="lines,vars,source" compiler="${build.compiler}">
			<classpath refid="classpath" />
		</javac>
		<copy todir="${bin}">
			<fileset dir="${java}" includes="**/*.xml" />
			<fileset dir="${javatest}" includes="**/*.xml" />
		</copy>
	</target>

	<target name="test" depends="junit-compile" description="Unit test">
		<mkdir dir="${test-reports}" />
		<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes" dir="${project.root}">
			<formatter type="plain" usefile="flase" />
			<formatter type="xml" />
			<test name="TestSuite" todir="${test-reports}">
			</test>
			<classpath refid="classpath" />
		</junit>
	</target>

	<target name="war" depends="compile">
		<delete dir="${dist}" />
		<mkdir dir="${dist}" />
		<jar destfile="${dist}/${ant.project.name}.war">
			<manifest>
				<attribute name="Built-By" value="${user.name}" />
				<attribute name="Specification-Version" value="${project.version}" />
			</manifest>
			<fileset dir="${web}">
				<exclude name="**/jsp-api.jar" />
				<exclude name="**/cfg.properties" />
				<exclude name="**/log4j.properties" />
			</fileset>
		</jar>
	</target>

	<!-- Configure the directory into which the web application is built -->
	<property name="build" value="${dist}/" />

	<!-- Configure the context path for this application -->
	<property name="path" value="/${ant.project.name}" />

	<!-- Configure properties to access the Manager application -->
	<property name="url" value="http://${remote.host.ip}:${remote.host.port}/manager" />
	<!--
	<property name="url" value="http://localhost:8080/manager" />
	-->
	<property name="username" value="manager" />
	<property name="password" value="manager" />

	<!-- Configure the custom Ant tasks for the Manager application -->
	<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
	<taskdef name="list" classname="org.apache.catalina.ant.ListTask" />
	<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" />
	<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask" />
	<taskdef name="roles" classname="org.apache.catalina.ant.RolesTask" />
	<taskdef name="start" classname="org.apache.catalina.ant.StartTask" />
	<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
	<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

	<target name="deploy" description="Install web application" depends="war">
		<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="file:${build}${ant.project.name}.war" update="true" />
	</target>

	<target name="reload" description="Reload web application" depends="war">
		<reload url="${url}" username="${username}" password="${password}" path="${path}" />
	</target>

	<target name="undeploy" description="Remove web application">
		<undeploy url="${url}" username="${username}" password="${password}" path="${path}" />
	</target>

	<target name="startup" description="Startup tomcat">
		<sshexec host="${remote.host.ip}" username="mwuser" password="mwuser" trust="true" command="/mwbase/tomcat/biztomcats/bin/svc" />
	</target>

	<target name="shutdown" description="Shutdown tomcat">
		<sshexec host="${remote.host.ip}" username="mwuser" password="mwuser" trust="true" command="/mwbase/tomcat/biztomcats/bin/dvc" />
	</target>
    <!--
	<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />
	<property name="findbugs.home" value="${env.FINDBUGS_HOME}" />
	<path id="findbugs.lib">
		<fileset dir="${findbugs.home}/lib">
			<include name="findbugs-ant.jar" />
		</fileset>
	</path>
	<taskdef name="convertXmlToText" classname="edu.umd.cs.findbugs.anttask.ConvertXmlToTextTask">
		<classpath refid="findbugs.lib" />
	</taskdef>
	<target name="convertXmlToHtml">
		<convertXmlToText home="${findbugs.home}" format="html" input="${report}/${ant.project.name}-fb.xml" output="${report}/${ant.project.name}-fb.html">
		</convertXmlToText>
	</target>
	<target name="findbugs" depends="compile" description="Find bugs">
		<delete dir="${report}" />
		<mkdir dir="${report}" />
		<findbugs home="${findbugs.home}" output="xml" outputFile="${report}/${ant.project.name}-fb.xml" failOnError="true" warningsProperty="findbugsFailure">
			<auxClasspath>
				<fileset dir="${lib}">
					<include name="*.jar" />
				</fileset>
			</auxClasspath>
			<sourcePath path="${java}" />
			<auxAnalyzepath path="${bin}" />
		</findbugs>
		<antcall target="convertXmlToHtml" />
		<fail if="findbugsFailure" />
	</target>
   -->
	<taskdef resource="checkstyletask.properties" classpath="${env.CHECKSTYLE_HOME}/checkstyle-5.3-all.jar" />

	<target name="checkstyle" description="Generates a report of code convention violations.">
		<mkdir dir="${report}" />
		<checkstyle config="${env.CHECKSTYLE_HOME}/sun_checks.xml" failureProperty="checkstyle.failure" failOnViolation="false">
			<formatter type="xml" tofile="${report}/checkstyle_report.xml" />
			<fileset dir="${java}" includes="**/*.java" />
		</checkstyle>
		<style in="${report}/checkstyle_report.xml" out="${report}/checkstyle_report.html" style="${env.CHECKSTYLE_HOME}/contrib/checkstyle-simple.xsl" />
	</target>

</project>


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:100882次
    • 积分:1665
    • 等级:
    • 排名:千里之外
    • 原创:64篇
    • 转载:27篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论