ant 的使用

首先参考http://www.iteye.com/topic/78973

最近换MyEclipse为Eclipse Tomcat不能自动布署,所以ant就是道选了

首先build.xml

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="default" name="Kodak-Tool-WebAntDemo">
	<!-- 导入project/build-impl.xml文件 -->
	<import file="project/build-impl.xml" />
</project>

其次project/build-impl.xml

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir=".">
	<!-- 读取project.properties文件 -->
	<property file="project/project.properties" />
	<property name="app.title" value="${project.title}" />
	<property name="app.version" value="${project.version}" />
	<property name="app.tomcat" value="${project.tomcat.path}" />
	<property name="app.build" value="${build.path}" />
	<property name="app.src" value="${src.path}" />
	<property name="app.dist" value="${dist.path}" />
	<property name="app.encode" value="${project.encode}" />

	<target name="default" depends="init,mk-war">
		<echo>"${app.title} compile success"</echo>
	</target>

	<target name="clean">
		<delete dir="${app.build}" />
		<delete dir="${app.dist}" />
		<!-- 清理Tomcat -->
		<delete file="${app.tomcat}/webapps/${app.title}.war" />
		<delete dir="${app.tomcat}/webapps/${app.title}" />
	</target>

	<target name="init" depends="clean">
		<mkdir dir="${app.build}" />
		<mkdir dir="${app.dist}" />
	</target>

	<target name="copy-file-to-WebRoot">
		<copy todir="${app.build}">
			<fileset dir="WebRoot" />
		</copy>
	</target>

	<target name="copy-jar-to-lib" depends="copy-file-to-WebRoot">
		<copy todir="${app.build}/WEB-INF/lib">
			<fileset dir="${common.classpath.path}" />
			<fileset dir="${dataBase.classpath.path}" />
			<fileset dir="${Hibernate.classpath.path}" />
			<fileset dir="${J2EE.classpath.path}" />
			<fileset dir="${log4j.classpath.path}" />
			<fileset dir="${other.classpath.path}" />
			<fileset dir="${Struts2.classpath.path}" />
		</copy>
	</target>

	<target name="run-compile" depends="copy-jar-to-lib">
		<!-- 资源文件的复制 -->
		<copy todir="${app.build}/WEB-INF/classes">
			<fileset dir="${app.src}">
				<exclude name="**/*.java" />
			</fileset>
		</copy>
		<javac destdir="${app.build}/WEB-INF/classes" encoding="${app.encode}">
			<classpath path="${app.build}/WEB-INF/lib" />
			<src path="${app.src}" />
		</javac>
	</target>

	<target name="mk-war" depends="run-compile">
		<war warfile="${app.dist}/${app.title}.war" needxmlfile='false'>
			<fileset dir="${app.build}" />
		</war>
		<!-- 布署到Tomcat下 -->
		<copyfile dest="${app.tomcat}/webapps/${app.title}.war" src="${app.dist}/${app.title}.war" />
	</target>
</project>

 使用用到的project/project.properties文件

 

project.title=Kodak-Tool-WebAntDemo
project.version=1.0.2
project.tomcat.path=F:/server/apache-tomcat-6.0.29
project.encode=UTF-8
build.path=build
src.path=src
dist.path=dist
common.classpath.path=lib/common
dataBase.classpath.path=lib/dataBase
Hibernate.classpath.path=lib/Hibernate
J2EE.classpath.path=lib/J2EE
log4j.classpath.path=lib/log4j
other.classpath.path=lib/other
Struts2.classpath.path=lib/Struts2

 这里使用project.properties目的就不多说了.

 

 

 

最后要说是的多个依赖包合成一个超级Jar包,网上查到的具体有两种思路:

1  用ant把Jar包拆开,然后合在一个Jar包里.

2 把所有的Jar以压缩包的形式合并,然后重写ClassLoader,来加载它们

这两种方式Eclipse都是支持的.Eclipse下还有一种就是通过在MANIFEST.MF中指定classpath的方式,指定依赖Jar.

你可能感兴趣的:(tomcat,Hibernate,log4j,xml,ant)