1:在eclipse中建立如下的工程

值得注意的就是build.xml文件(这个是重点后面会提到) ,其他HelloWorld中的就是一句简单的输出语句

2: 使用build打包(右键然后选择运行),运行后在console下可以看到如下图的过程

当看到了BUILD SUCCESSFUL 表面打包成功了!!!!

3:然后来到你的**\dist下可以看到刚刚打包成功的包 如下图 :

4:ANT很智能的,如果你已经实现了上面三个过程的打包,再次打包的话它会默认的执行空的操作 (如下图)

5:最重要的bulid.xml文件(此中有很多ANT内置的命令可以具体参考一下ant的用法)

  1. <project name="HelloWorld" default="jar" basedir=".">
  2. <description>
  3. building HelloWorld!
  4. </description>
  5. <!-- set global properties for this build -->
  6. <property name="src" location="src"/>
  7. <property name="build" location="classes"/>
  8. <property name="dist"  location="dist"/>
  9. <property name="user.name" value="qiuqiu"/>
  10. <target name="init">
  11. <!-- Create the time stamp -->
  12. <tstamp/>
  13. <!-- Create the classes directory structure used by compile -->
  14. <mkdir dir="${build}"/>
  15. </target>
  16. <target name="build" depends="init"  description="build the source code" >
  17. <!-- Compile the java code from ${src} into ${build} -->
  18. <javac srcdir="${src}" destdir="${build}"/>
  19. </target>
  20. <target name="jar" depends="build"
  21. description="generate the distribution" >
  22. <!-- Create the distribution directory -->
  23. <mkdir dir="${dist}/lib"/>
  24. <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
  25. <jar destfile="${dist}/HelloWorld-${DSTAMP}.jar" basedir="${build}">
  26. <manifest>
  27. <attribute name="Built-By" value="${user.name}"/>
  28. <attribute name="Main-Class" value="org.javaresearch.HelloWorld"/>
  29. </manifest>
  30. </jar>
  31. </target>
  32. <target name="run" depends="build" description="run HelloWorld">
  33. <java classpath="${build}" classname="org.javaresearch.HelloWorld"></java>
  34. </target>
  35. <target name="runjar" depends="jar" description="run HelloWorld in jar file">
  36. <java jar="${dist}/HelloWorld-${DSTAMP}.jar"
  37. fork="true"
  38. failonerror="true"
  39. maxmemory="128m"
  40. >
  41. <arg value="-h"/>
  42. <classpath>
  43. <pathelement location="${dist}/HelloWorld-${DSTAMP}.jar"/>
  44. <pathelement path="${java.class.path}"/>
  45. </classpath>
  46. </java>
  47. </target>
  48. <target name="clean"
  49. description="clean up" >
  50. <!-- Delete the ${build} and ${dist} directory trees -->
  51. <delete dir="${build}"/>
  52. <delete dir="${dist}"/>
  53. </target>
  54. </project>
<project name="HelloWorld" default="jar" basedir=".">
<description>
building HelloWorld!
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="classes"/>
<property name="dist" location="dist"/>
<property name="user.name" value="qiuqiu"/> <target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the classes directory structure used by compile -->
<mkdir dir="${build}"/>
</target> <target name="build" depends="init" description="build the source code" >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target> <target name="jar" depends="build"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar destfile="${dist}/HelloWorld-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="org.javaresearch.HelloWorld"/>
</manifest>
</jar>
</target> <target name="run" depends="build" description="run HelloWorld">
<java classpath="${build}" classname="org.javaresearch.HelloWorld"></java>
</target> <target name="runjar" depends="jar" description="run HelloWorld in jar file">
<java jar="${dist}/HelloWorld-${DSTAMP}.jar"
fork="true"
failonerror="true"
maxmemory="128m"
>
<arg value="-h"/>
<classpath>
<pathelement location="${dist}/HelloWorld-${DSTAMP}.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target> <target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

6:ant使用指南(为了方便没有资源分的朋友下载,这里给大家0资源分): http://download.csdn.net/source/3529167

有不足之处欢迎指正

图解教你如何使用ANT打包java程序的更多相关文章

  1. 使用Ant打包Java后台程序

    概述 本文通过一个简单的Java Application例子描述如何用ANT完成基本的程序打包工作.包含文件拷贝.编译.打包三部分:完成这三部就可以得到一个可运行的程序包了. ANT的安装,环境变量的 ...

  2. 使用exe4j打包Java程序

    工具: exe4j软件(云盘存) 可以运行的Java程序的jar包 打开我们已经安装好的exe4j软件,首先看到的是一个欢迎界面,我们直接[next]就可以了: 2 在第二步中我们选择[JAR in ...

  3. idea 打包java程序

    创建maven项目 在pom.xml中添加: <build> <plugins> <plugin> <groupId>org.apache.maven. ...

  4. 打包java程序生成exe

    打包java程序生成exe 目标 我们知道c++的控制台程序编译运行以后就会生成一个exe可执行文件,在电脑上可以直接双击运行,但是java是跨平台的语言,编译运行以后的字节码文件.class是和平台 ...

  5. 在Linux下通过rpm打包发布Java程序

    这个东西涉及的内容较多,根据下面这些文章慢慢学习 一个简单的例子 http://blog.csdn.net/king_on/article/details/7169384 按照文章中的步骤来,打包之后 ...

  6. JAVA程序打包成exe文件详细图解

    我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: eclipse ...

  7. 一招教你IDEA中Java程序如何打包,以及打包后如何运行

    前言 编写程序 程序打包 测试运行 IDEA作为目前按最主流的Java程序项目编写工具,越来越受到开发人员的青睐.idea因为其五花八门的功能,让你在开发过程中效率显著提高.那么对于初学者来说,如何通 ...

  8. 用Ant实现Java项目的自动构建和部署

    原文地址:http://tech.it168.com/j/2007-11-09/200711091344781.shtml         本文请勿转载! Ant是一个Apache基金会下的跨平台的构 ...

  9. 不会用ant打包、部署项目的工程师,不是一个好程序员(测试)

    副标题:利用ant脚本 自动构建svn增量/全量 系统程序升级包 首先请允许我这样说,作为开发或测试,你一定要具备这种本领.你可以手动打包.部署你的工程,但这不是最好的方法.最好的方式就是全自动化的方 ...

随机推荐

  1. 1017A.The Rank#排名

    题目出处:http://codeforces.com/problemset/problem/1017/A #include<iostream> using namespace std; i ...

  2. 刷题41. First Missing Positive

    一.题目说明 题目是41. First Missing Positive,求一个未排序队列中缺失的最小正整数.时间复杂度要求是O(n).难度是Hard,确实难. 二.我的解答 不考虑时间复杂度,首先对 ...

  3. UG NX7.5 采用VS2008调试方法

    1.安装NX7.5(x64),这是废话 2.安装visual studio 2008,推荐安装2008,如果是2010应该也可以用,(没有测试,不清楚) 3.复制 UGS\NX 7.5\UGOPEN\ ...

  4. StartDT AI Lab | 智能运筹助力企业提升决策效率、优化决策质量

    在人工智能和大数据时代,越来越多的云上数据和越来越智能的模型开始辅助人们做出各种最优决策,从运营效率.成本节约.最优配置等方方面面,实现降本增效,进一步提升商业效率.京东.美团.滴滴.顺丰等众多知名厂 ...

  5. 树莓派docker搭建

    树莓派上 Docker 的安装和使用 Docker 是一个开源的应用容器引擎,可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟 ...

  6. 大数据学习——MapReduce学习——字符统计WordCount

    操作背景 jdk的版本为1.8以上 ubuntu12 hadoop2.5伪分布 安装 Hadoop-Eclipse-Plugin 要在 Eclipse 上编译和运行 MapReduce 程序,需要安装 ...

  7. ZJNU 1153 - 找单词——中级

    状态转移b[i]记录价值为i的单词种类数d[j+k*i]+=b[j] , k<=a[i]&&j+k*i<=50表示价值为j+k*i的单词可以由价值为j的单词加上k个i字母转 ...

  8. Monkey通过安装包获取包名

    在monkey命令中,包名常作为一个参数.但我们经常知道apk文件,却不知道包名. 如何获取包名呢? 方法一:AAPT 在SDK的build-tools目录下,aapt工具可以查看,创建,更新zip格 ...

  9. VScode中Python的交互式命令环境使用笔记

    前言 时间比较久了,忘记了具体配置了,不讲搭建了,提供参https://www.zhihu.com/question/49799276,或自行谷歌,常用的插件Python和Code Runner. 本 ...

  10. Linux常用指令(三)

    进入京东运维组实习,收到了很多同事的热心指导,自己也努力学习,按照他们给出的学习计划,真的很充实,学到了很多不只是开发方面的知识. 以下简单记录下自己的笔记,方便以后查阅. 1.文件系统 Linux系 ...