图解教你如何使用ANT打包java程序
1:在eclipse中建立如下的工程

值得注意的就是build.xml文件(这个是重点后面会提到) ,其他HelloWorld中的就是一句简单的输出语句
2: 使用build打包(右键然后选择运行),运行后在console下可以看到如下图的过程

当看到了BUILD SUCCESSFUL 表面打包成功了!!!!
3:然后来到你的**\dist下可以看到刚刚打包成功的包 如下图 :

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

5:最重要的bulid.xml文件(此中有很多ANT内置的命令可以具体参考一下ant的用法)
- <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>
<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程序的更多相关文章
- 使用Ant打包Java后台程序
概述 本文通过一个简单的Java Application例子描述如何用ANT完成基本的程序打包工作.包含文件拷贝.编译.打包三部分:完成这三部就可以得到一个可运行的程序包了. ANT的安装,环境变量的 ...
- 使用exe4j打包Java程序
工具: exe4j软件(云盘存) 可以运行的Java程序的jar包 打开我们已经安装好的exe4j软件,首先看到的是一个欢迎界面,我们直接[next]就可以了: 2 在第二步中我们选择[JAR in ...
- idea 打包java程序
创建maven项目 在pom.xml中添加: <build> <plugins> <plugin> <groupId>org.apache.maven. ...
- 打包java程序生成exe
打包java程序生成exe 目标 我们知道c++的控制台程序编译运行以后就会生成一个exe可执行文件,在电脑上可以直接双击运行,但是java是跨平台的语言,编译运行以后的字节码文件.class是和平台 ...
- 在Linux下通过rpm打包发布Java程序
这个东西涉及的内容较多,根据下面这些文章慢慢学习 一个简单的例子 http://blog.csdn.net/king_on/article/details/7169384 按照文章中的步骤来,打包之后 ...
- JAVA程序打包成exe文件详细图解
我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: eclipse ...
- 一招教你IDEA中Java程序如何打包,以及打包后如何运行
前言 编写程序 程序打包 测试运行 IDEA作为目前按最主流的Java程序项目编写工具,越来越受到开发人员的青睐.idea因为其五花八门的功能,让你在开发过程中效率显著提高.那么对于初学者来说,如何通 ...
- 用Ant实现Java项目的自动构建和部署
原文地址:http://tech.it168.com/j/2007-11-09/200711091344781.shtml 本文请勿转载! Ant是一个Apache基金会下的跨平台的构 ...
- 不会用ant打包、部署项目的工程师,不是一个好程序员(测试)
副标题:利用ant脚本 自动构建svn增量/全量 系统程序升级包 首先请允许我这样说,作为开发或测试,你一定要具备这种本领.你可以手动打包.部署你的工程,但这不是最好的方法.最好的方式就是全自动化的方 ...
随机推荐
- ZJNU 2201 - 挖矿谷物语
在dfs过程中加上栈记录当次dfs走过的路径 如果当次dfs到了一个之前的dfs已经经过的点 又因为只对没有访问过的点开始dfs 所以这种情况就说明接下来不可能返回到当次dfs开始的点 将栈内元素取出 ...
- myeclipse跟tomcat的同步
一般来说,我们在myeclipse里把文件内容改了并保存之后,直接刷新网页就可以非常直观的看到内容的改变. 这是因为myeclipse检测到文件内容的变动,及时地把新的文件部署到了tomcat上. m ...
- [LC] 82. Remove Adjacent Repeated Characters IV
Repeatedly remove all adjacent, repeated characters in a given string from left to right. No adjacen ...
- mysql之存储过程(三)
带参数的存储过程: 特别说明: 在游标中是不支持对形参的判断的,外部可以 调用操作: call settlexxxxx_common("1970-11",999); 定义如下: ...
- vue路由的跳转-路由传参-cookies插件-axios插件-跨域问题-element-ui插件
---恢复内容开始--- 项目初始化 创建一个纯净的vue环境项目,手动书写全局的样式配置,全局的main,js配置 (1)如果vue项目在重构或者出错的时候,手动安装node_modules. 如果 ...
- 892A. Greed#贪婪(优先队列priority_queue)
题目出处:http://codeforces.com/problemset/problem/892/A 题目大意:有一些可乐(不一定装满),问能不能把所有可乐装进两个可乐瓶中 #include< ...
- Codeforces Round #559(Div.1)
A 签到贪心题,特判了n=1或m=1的情况才发现2<=n,m<=1e5 #include<bits/stdc++.h> using namespace std; typedef ...
- linux 添加常用长命令别名
## 设置linux下常用命令别名,提高效率 将要使用的命令别名写入到~/.bashrc文件,通过source ~/.bashrc命令使变更生效 alias sst='systemctl status ...
- Python2 和 Python3的区别 更新中
py2和py3的区别 1.默认解释器编码 py2: ascii py3: utf-8 2.输入 输出 输入 py2: name = raw_input('请输入你的姓名:') py3: name = ...
- 使用java获取手机号归属地等信息httpClient实现
java获取手机号归属地 一般想获取手机号归属地等信息个人是无法获取的,但是可以通过调用第三方接口获取,具体百度搜索很多这里例子提供一个淘宝的接口 ,该功能已经发布到网站作为一个在线小工具,拿走不谢: ...