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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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包生成:



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值