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的结构


ant简单操作ant编译web工程war包
 8、打开cmd窗口,进行工程目录,如:D:\Program Files\Workspaces\ant

输入ant,回车

显示如下:

 
ant简单操作ant编译web工程war包
 9、war包生成:


ant简单操作ant编译web工程war包
 

相关文章:

  • 2021-09-09
  • 2021-09-06
  • 2021-12-21
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2022-02-13
  • 2021-07-31
  • 2021-12-16
  • 2021-10-01
  • 2021-06-06
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案