1、首先下载apache ant 下载页面:http://ant.apache.org/bindownload.cgi
2、把下载的压缩包解压到你的工作文件夹下,例:E:\开发文档\打包工具\apache-ant-1.9.4
3、配置环境变量:
(1)变量:ANT_HOME 值:E:\开发文档\打包工具\apache-ant-1.9.4
ANT_HOME变量的值就是解压ant的路径。
(2)在变量path下,添加%ANT_HOME%\bin
4、打开cmd窗口,输入ant,回车。
如果显示下面的字符串,配置正确。
C:\Users\admin>ant
Buildfile: build.xml does not exist!
Build failed
5、打开MyEclipse新建一个web工程。
新建一个类HelloWorld.java
package test;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
6、在工程下新建一个build.xml文件
配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="run" basedir=".">
<target name="init">
<copy todir="WebRoot/WEB-INF/classes">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="WebRoot/WEB-INF/classes" includeantruntime="on" />
</target>
<target name="build" depends="compile">
<war warfile="HelloWorld.war" webxml="WebRoot/WEB-INF/web.xml">
<fileset dir="WebRoot">
<excludesfile name="WebRoot/WEB-INF/web.xml" />
<excludesfile name="build.xml"/>
<exclude name="WebRoot/WEB-INF/lib" />
</fileset>
</war>
</target>
<target name="run" depends="build" />
</project>
7、web工程在myeclipse的结构

8、打开cmd窗口,进行工程目录,如:D:\Program Files\Workspaces\ant
输入ant,回车
显示如下:

9、war包生成:

使用Apache Ant构建MyEclipse Web工程并生成WAR包
本文详细介绍了如何在MyEclipse中配置Apache Ant环境,为Web工程创建build.xml文件,实现从源代码到生成WAR包的自动化构建流程。
1万+

被折叠的 条评论
为什么被折叠?



