Ant 构建 打包 发布

Ant
一.简介
Ant,构建,打包,编译自动化工具。
二.下载地址 三.例子

Ant 构建 打包 发布
图1.1 项目架构

#project name
app.NAME=OWNUSESYSTEM
app.name=OwnUseSystem

#tomcat home
tomcat.dir=D:/software/apache-tomcat-7.0.29-windows-x64/apache-tomcat-7.0.29

#compile path
build.dir=build
build.classes.dir=${build.dir}/classes

#source code path
source.dir=src
#config path
resource.dir=config
#output file
log.file=D:/ming.txt
#java path
java.lib.dir=C:/Program Files (x86)/Java/jdk1.6.0_13/jre/lib
#WebContent path
WebContent.dir=WebContent
WebContent.WebInf.dir=${WebContent.dir}/WEB-INF
WebContent.DB.dir=${WebContent.dir}/DB
WebContent.WebInf.classes.dir=${WebContent.WebInf.dir}/classes
WebContent.WebInf.lib.dir=${WebContent.WebInf.dir}/lib

#dist 
dist.dir=ming
dist.db.dir=${dist.dir}/db

#sqlserver configuration 
sqlserver.dbname=owern
sqlserver.username=sa
sqlserver.password=123

<?xml version="1.0" encoding="utf-8" ?>
<project name ="OwnUseSystem" default ="run" basedir ="."><!--默认调用run-->
    <property file="build.properties"></property><!--引入文件用来 配置路径-->
	<path id="compile_path"><!--定义环境变量-->
		   <fileset dir="${WebContent.WebInf.lib.dir}">
		       <include name="**/*.jar"/>
		   </fileset>
		   <fileset dir="${tomcat.dir}/lib">
		       <include name="servlet-api.jar"/>
		   </fileset>
		   <pathelement path="${build.classes.dir}" />
	</path>
	<target name="create" depends="clean"><!--创建文件目录-->
		<echo message="create ming build "></echo>
		<mkdir dir="${build.dir}"/><!--创建编译文件夹-->
		<mkdir dir="${build.classes.dir}"/><!--创建编译文件夹 classes-->
		<mkdir dir="${dist.dir}"/><!--create ming-->
		<mkdir dir="${dist.db.dir}"/><!--创建ming文件夹 db-->
		<mkdir dir="${WebContent.WebInf.classes.dir}"/><!--创建webinf classes-->
	</target>
	<target name="copyConfig" depends="create">
		<copy todir="${build.classes.dir}">
			<fileset dir="${resource.dir}" >
			    <include name="**/*.properties" />
			    <include name="**/*.xml" />
			    <!--<exclude name="applicationContext.xml" />-->
			 </fileset>
		</copy>
		<copy todir="${dist.db.dir}">
			<fileset dir="${resource.dir}">
			    <include name="init.sql"/>
			</fileset>
	    </copy>
		<!-- execute the sql script -->
		<sql 
		            driver="com.mysql.jdbc.Driver"
		            url="jdbc:sqlserver://localhost/${sqlserver.dbname}" 
		            userid="${sqlserver.username}"
		            password="${sqlserver.password}"
		            src="${dist.db.dir}/init.sql"
		            classpathref="compile.classpath">
		</sql>
	</target>
	<target name="compile" depends="copyConfig">
		<javac srcdir="${source.dir}" destdir="${build.classes.dir}"     classpathref="compile_path">
		     <compilerarg line="-encoding UTF-8 "/> 
		 </javac>
		 <copy todir="${build.classes.dir}">
			  <fileset dir="${source.dir}">
			    <include name="**/*.hbm.xml"/>
			  </fileset>
		 </copy>
		 <copy todir="${WebContent.WebInf.classes.dir}">
		             <fileset dir="${build.classes.dir}">
		             </fileset>
		 </copy>
	</target>
	<target name="war" depends="compile"><!--打war包-->
		 <war warfile="${dist.dir}/${app.name}.war" webxml="${WebContent.WebInf.dir}/web.xml">
		    <fileset dir="${WebContent.dir}"></fileset>
		 </war>
	</target>
	<target name="deploy" depends="war">
		<echo message="deploy the project to a web server" />
		<copy todir="${tomcat.dir}/webapps">
		      <fileset file="${dist.dir}/${app.name}.war"></fileset>
		</copy>
	</target>
    <target name="run" depends="deploy"><!--启动tomcat-->
    	<echo message="start tomcat" />
    	 <exec executable="cmd" dir="${tomcat.dir}/bin"  failonerror="false"   
    	                    output="${log.file}" append="true" >  
    	             <!-- <arg value="/c" /> -->    
    	             <env key="CATALINA_HOME" path="${tomcat.dir}"/>  
    	             <arg value="/c startup.bat" />     
    	 </exec>  
    </target>
    <target name="clean"><!--清除构建目录-->
    	<echo message="basedir is ${basedir}"></echo>
        <delete dir="${dist.dir}"></delete><!--清除目标路径-->
    	<delete dir="${WebContent.WebInf.classes.dir}"></delete>
        <!--清除webcontent class路径-->
    	<delete dir="${build.dir}"></delete><!--清除编译路径-->
    	<delete file="${tomcat.home}/webapps/${app.name}.war" /><!--删除war包-->
    	<delete dir="${tomcat.home}/webapps/${app.name}" /><!--删除项目-->
    </target>

</project>

你可能感兴趣的:(jvm,ant)