弄了好久的ant打包终于明白了,贴出来大家分享。
<?xml version="1.0" encoding="UTF-8"?>
<project name="gpdi" basedir="." default="deploy">
<!-- Properties and Paths -->
<property name="dir.java.src" value="src" />
<property name="dir.java.build" value="defaultroot/WEB-INF/classes" />
<property name="dir.lib" value="lib" />
<property name="dir.deploy" value="deploy" />
<property name="file.manifest" value="manifest.txt" />
<property name="file.jar" value="gpdi.jar" />
<!-- Just to fool the test -->
<property name="gpdi.root" value="." />
<!-- 排除java源文件的模式集 -->
<patternset id="no.java">
<exclude name="**/*.java" />
</patternset>
<path id="project.class.path">
<pathelement location="${dir.java.build}"/>
<fileset dir="${dir.lib}" id="lib.path">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- 初始化,建立目录,复制文件 -->
<target name="init" depends="clean" description="初始化,建立目录,复制文件">
<mkdir dir="${dir.java.build}" />
<mkdir dir="${dir.dist}" />
<copy todir="${dir.java.build}">
<fileset dir="${dir.java.src}">
<patternset refid="no.java" />
</fileset>
</copy>
</target>
<!-- 清理,删除临时目录 -->
<target name="clean" description="清理,删除临时目录">
<delete dir="${dir.java.build}" />
<delete dir="${dir.dist}" />
<echo level="info">清理完毕</echo>
</target>
<!-- 编译源文件-->
<target name="compile"
depends="init"
description="编译源文件">
<javac srcdir="${dir.java.src}"
destdir="${dir.java.build}"
deprecation="off"
debug="off"
encoding="gbk"
source="1.5"
target="1.5">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- 创建清单文件 -->
<target name="create.manifest" description="创建清单文件">
<manifest file="${dir.java.src}/${file.manifest}">
<attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="com.mfsoft.net.task.TaskJob" />
<attribute name="Class-Path" value="lib/log4j-1.2.9.jar lib/classes12.jar lib/joone-engine.jar" />
</manifest>
</target>
<!-- 打包类文件 -->
<target name="deploy" depends="create.manifest" description="打包类文件">
<mkdir dir="${dir.deploy}" />
<mkdir dir="${dir.deploy}/log" />
<jar jarfile="${dir.deploy}/${file.jar}" manifest="${dir.java.src}/${file.manifest}">
<fileset dir="${dir.java.build}" includes="db.properties,config.properties,log4j.properties,com/mfsoft/net/task/*.class,com/mfsoft/credit/modelmang/operation/*.class,
com/mfsoft/net/datatranslate/*.class,com/mfsoft/net/pre/*.class,com/mfsoft/icity/platform/database/*.class,com/mfsoft/icity/platform/datashare/*.class,
com/mfsoft/icity/platform/publicclass/*.class,com/mfsoft/credit/viable/*.class" />
</jar>
<!--复制用到的库以及其他文件 -->
<mkdir dir="${dir.deploy}/lib"/>
<copy todir="${dir.deploy}/lib">
<fileset dir="defaultroot/WEB-INF/lib" includes="classes12.jar,joone-engine.jar,log4j-1.2.9.jar"/>
</copy>
<mkdir dir="${dir.deploy}/model"/>
<copy todir="${dir.deploy}/model">
<fileset dir="defaultroot/WEB-INF/classes" includes="*.snet"/>
</copy>
</target>
</project>