<project name="test" default="default" basedir=".">
<target name="zip">
<zip basedir="test" destfile="test.zip">
</zip>
</target>
</project>
___________________________________________________________________________
以上是完整的build.xml文件,在build文件所在目录打开终端运行命令:ant zip
即可将basedir指定的目录打包成destfile指定的压缩包
PS:也可以在basedir与destfile指定文件的路径,此处默认与build.xml文件同一目录下。
1.首先确认,你的linux上有没有安装ant2.确认你的 各种环境是否配置正确(不会的话去看hadoop开发指南)
我把我的build.xml发给你
<?xml version="1.0"?>
<!--build.xml - a simple Ant buildfile -->
<project name="Simple Buildfile" default="compile" basedir=".">
<!--Set up the env prefix for environment variable -->
<property environment="env"/>
<!-- The directory cotaining source code -->
<property name="src.dir" value="src" />
<!-- Temporary build directories -->
<property name="build.dir" value="build"/>
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.lib" value="${build.dir}/lib"/>
<property name="jar.name" value="howtouse.jar"/>
<!-- Hadoop path -->
<property name="hadoop.path" value="${env.HADOOP_HOME}"/>
<!-- Target to create the build directories prior to the -->
<!-- compile target -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.lib}"/>
</target>
<target name="clean" description="Removes all generated files.">
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="prepare" description="Compiles all source code.">
<javac srcdir="${src.dir}" destdir="${build.classes}" includeantruntime="false"
deprecation="false">
<classpath>
<pathelement location="${hadoop.path}/hadoop-core-0.20.203.0.jar"/>
<pathelement location="${hadoop.path}/hadoop-tools-0.20.203.0.jar"/>
<pathelement location="${hadoop.path}/hadoop-examples-0.20.203.0.jar"/>
<pathelement location="${hadoop.path}/lib/mockito-all-1.8.5.jar"/>
<pathelement location="${hadoop.path}/lib/junit-4.5.jar"/>
<pathelement location="${hadoop.path}/lib/commons-math-2.1.jar"/>
<pathelement location="${hadoop.path}/lib/commons-cli-1.2.jar"/>
<pathelement location="${hadoop.path}/contrib/datajoin/hadoop-datajoin-0.20.203.0.jar"/>
</classpath>
</javac>
</target>
<target name="jar" depends="compile" description="Generates jar in the dist directory.">
<!-- Exclude unit tests from the final Jar file -->
<jar jarfile="${jar.name}" basedir="${build.classes}" excludes="**/*Test.class"/>
</target>
<target name="all" depends="clean,jar" description="Cleans,compiles,then builds the Jar file."/>
</project>
确保以上条件后
1.将自己写的java文件放到 /home/hadoop/ant/build/src 使用XFTP
2.在HDFS中新建一个文件目录专门用来装资源文件 hadoop fs -mkdir /user/src
3.将simple.txt测试文件放到HDFS中 hadoop fs -put/user/src
4.将/home/hadoop/ant/build/src下的java文件编译打包成play.jar(名字由build.xml决定)
方法:编译之前必须保证与build.xml同级目录下 ant jar
5.hadoop单机模式运行的时候必须保证在lib目录下
hadoop jar play.jar hadoop/MaxTemperature /user/src/simple.txt output
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)