1, mkdir - javac - jar - java - delete
2, includes 引进lib中的jar包, 在javac 和 java 的target的中都要用到
3, 单独运行这个jar包, 需要将jar包信息打到 MANIFEST.MF 中。 将lib目录copy的当前目录
2, includes 引进lib中的jar包, 在javac 和 java 的target的中都要用到
3, 单独运行这个jar包, 需要将jar包信息打到 MANIFEST.MF 中。 将lib目录copy的当前目录
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_02-b06 (Sun Microsystems Inc.)
Main-Class: com.tristan.AntTest
Class-Path: . lib/UCMDBAdapter.jar lib/antlr.jar lib/commons-beanutils
.jar lib/commons-dbcp-1.2.2.jar lib/commons-dbutils-1.3.jar lib/commo
ns-digester.jar lib/commons-fileupload.jar lib/commons-lang-2.4.jar l
ib/commons-logging.jar lib/commons-pool-1.5.4.jar lib/commons-validat
or.jar lib/dom4j-1.6.1.jar lib/jakarta-oro.jar lib/json_simple-1.1.ja
r lib/junit.jar lib/log4j-1.2.14.jar lib/ojdbc14.jar lib/org.hamcrest
.core_1.1.0.v20090501071000.jar lib/poi-3.6-20091214.jar lib/struts.j
ar lib/ucmdb-api.jar
<?xml version="1.0" ?>
<project name="structured" default="archive">
<property name="Main_Class" value="com.tristan.AntTest"/>
<property name="JAR_HOME" value="dist/project.jar"/>
<path id="tristan.classpath">
<fileset dir="lib" includes="*.jar"/>
</path>
<pathconvert property="manifest.classpath" pathsep=" ">
<path refid="tristan.classpath"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="lib/*.jar"/>
</chainedmapper>
</mapper>
</pathconvert>
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="dist" />
<copy todir="dist/lib">
<fileset dir="lib"/>
</copy>
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="build/classes" >
<classpath refid="tristan.classpath"/>
</javac>
</target>
<target name="archive" depends="compile">
<jar destfile="${JAR_HOME}" basedir="build/classes" >
<manifest>
<attribute name="Main-Class" value="${Main_Class}"/>
<attribute name="Class-Path" value=". ${manifest.classpath}" />
</manifest>
</jar>
</target>
<target name="clean" depends="init">
<delete dir="build" />
<delete dir="dist" />
</target>
<target name="run" depends="archive">
<java classname="com.tristan.AntTest" classpath="${JAR_HOME}">
<classpath refid="tristan.classpath"/>
</java>
</target>
</project>