Ant
使用Ant打包Jar
<?xml version="1.0" encoding="utf-8"?>
<!--
maven项目使用ant打包步骤
1.命令行执行mvn dependency:copy-dependencies
把依赖的jar copy到${project.path}/target/dependency/目录下.可以很容易的利用好Ant.
2.ant OR ant javadoc 打包程序或者生成文档
打包的程序一般在:${project.path}/target/dist/${version}/
JavaDoc文档一般在${project.path}/target/ant/javadoc/
-->
<project name="hadoop_itcast" basedir="." default="default">
<property environment="env"/>
<property name="version" value="1.0"/>
<property name="project" value="hadoop_itcast"/>
<property name="package" value="lxf"/>
<property name="domain" value="com"/>
<property name="author" value="lxf"/>
<property name="vendor" value="lxf"/>
<property name="src.dir" location="src/main/java"/>
<property name="test.dir" location="src/test/java"/>
<property name="config.dir" location="src/main/resources" />
<property name="build.dir" location="target/ant/classes" />
<property name="dist.dir" location="target/dist"/>
<property name="doc.dir" location="target/javadoc"/>
<!--<property name="web.root" location="src/main/webapp" />-->
<property name="lib.dir" location="target/dependency"/>
<property name="entry.class" value="com.lxf.bigdata.mr.wcdemo.WordCountDriver"/>
<!--准备目录 -->
<target name="prePair">
<echo>预处理</echo>
<mkdir dir="${dist.dir}"/>
<delete includeemptydirs="true" deleteonexit="true">
<fileset dir="${dist.dir}" includes="**/*.jar"/>
</delete>
<mkdir dir="${build.dir}"/>
</target>
<!-- 定义路径变量-->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/> <!--所要包含的jar:所有jar -->
</fileset>
</path>
<!--编译-->
<target name="compile" depends="prePair" description="编译">
<echo message="complie the source"/>
<javac srcdir="${src.dir}"
destdir="${build.dir}"
encoding="UTF-8"
includeantruntime="no"
includes="**/*.java"
source="1.8"
target="1.8"
deprecation="true"
failonerror="true"
debug="true">
<classpath refid="classpath"></classpath>
</javac>
<!--拷贝目录 -->
<copydir src="${config.dir}" dest="${build.dir}"></copydir>
</target>
<!--打包-->
<target name="package" depends="compile" description="打包">
<mkdir dir="${dist.dir}/${version}"/>
<tstamp description="时间戳">
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss"/>
<format property="TIME" pattern="yyMMddHHmm"/>
</tstamp>
<manifest file="${build.dir}/MANIFEST.MF">
<attribute name="Created-By" value="${author}"/>
<attribute name="Built-Date" value="${TODAY}"/>
<attribute name="Implementation-Title" value="${project}"/>
<attribute name="Implementation-Version" value="${version}"/>
<attribute name="Implementation-Vendor" value="${vendor}"/>
<attribute name="Main-Class" value="${entry.class}" />
</manifest>
<property name="jar.prefix" value="${dist.dir}/${version}/${domain}.${package}.${project}.bin.${version}.v${TIME}"/>
<jar destfile="${jar.prefix}.jar"
basedir="${build.dir}"
manifest="${build.dir}/MANIFEST.MF">
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar"/>
</jar>
</target>
<target name="clean" description="清空">
<delete dir="${build.dir}"/>
</target>
<target name="default" depends="package,clean">
<echo> done!!! </echo>
</target>
</project>