发现好多同事还在使用eclipse 来编译并发布应用,离开这个工具就行不通了,有必要写个Demo给大家参考。
脚本中的目录替换为自己的即可
<?xml version="1.0" encoding="UTF-8"?>
<project name="JMeterTest" basedir="." default="zip">
<!-- 定义常量 -->
<!--property file="build.properties"/-->
<property name="app-out" value="app"/>
<property name="app-zip" value="${ant.project.name}.zip"/>
<property name="app-jar" value="${ant.project.name}.jar"/>
<property name="app-lib" value="${basedir}/lib"/>
<property name="source-dir" value="src"/>
<property name="encoding" value="UTF-8"/>
<!-- 清空build目录 -->
<target name="clean">
<delete dir="${app-out}"></delete>
</target>
<!-- 编译源码 -->
<target name="build" depends="clean">
<path id="classpath">
<pathelement path="${app-out}/classes"/>
<fileset dir="${app-lib}">
<include name="*.jar"/>
</fileset>
</path>
<mkdir dir="${app-out}/classes"/>
<javac srcdir="${source-dir}"
destdir="${app-out}/classes"
classpathref="classpath"
debug="on"
includeantruntime="on"
encoding="${encoding}"
>
<include name="com/e9/**"/>
<include name="com/jason/**"/>
</javac>
<copy todir="${app-out}/classes" file="${source-dir}/logback.xml"></copy>
</target>
<!-- 将class文件打包成jar包 -->
<target name="jar" depends="build">
<jar destfile="${app-out}/${app-jar}" basedir="${app-out}/classes">
<include name="**"/>
<manifest>
<attribute name="Main-class" value="com/jason/test/startup"/>
</manifest>
</jar>
<echo>构建完成,请查看输出文件:${app-out}/${app-jar}</echo>
</target>
<!-- 将所有jar包压缩为zip文件,便于发布和传阅 -->
<target name="zip" depends="jar">
<zip destfile="${app-out}/${app-zip}">
<fileset dir="${app-out}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${app-lib}">
<include name="**/*.jar"/>
</fileset>
</zip>
<echo>构建完成,请查看输出文件:${app-out}/${app-zip}</echo>
</target>
</project>