2015-11-09 21:55:57
来 源
ITJS.CN
Apache
此文详细介绍Windows下Apacheant的安装与配置,希望对于初学Apache服务器相关的朋友有帮助,更多Apache安装、配置、报错处理等资源请本站内搜索。

下载Apache Ant 1.8.4http://ant.apache.org/bindownload.cgi

一、解压ant安装包在D:SWE下

二、环境变量配置

ANT_HOME D:SWEapache-ant-1.8.4

CLASSPATH ;%ANT_HOME%lib;

PATH ;%ANT_HOME%bin;

三、测试是否安装成功

在cmd命令方式下输入:ant -version

Apache <wbr>Ant安装与配置

出现问题:

1)Unable to locate tools.jar. Expected to find it in C:Program FilesJavajre6lib

命令行敲ant命令后提示:“Unable to locate tools.jar. Expected to find it in C:Program FilesJavajre6lib”;ANT_HOME环境变量已经配置;

解决途径:将“C:Program FilesJavajdk1.6.0_16lib”目录下的tools.jar文件拷贝到“C:Program FilesJavajre6lib”目录下,重新运行命令ant,运行正常,问题解决。

2)在cmd命令中:输入ant,如果输出: Buildfile:build.xml does not exist!

Build failed

说明ant安装成功。

四、运行第一个ant脚本

在D:ant_homeapache-ant-1.8.1bin下面新建目录build,再在该目录下新建目录src

同时在src目录下新建HelloWorld.java

内容如下:

  package test.ant;

public class HelloWorld{

public static void main(String[] args){

System.out.println("Hello World");

  }

  };

编写build.xml文件保存到D:ant_homeapache-ant-1.8.1bin

内容如下:

  <?xml version="1.0" encoding="UTF-8" ?>

  <project name="HelloWorld" default="run" basedir=".">

  <property name="src" value="build/src" />

  <property name="dest" value="build/classes" />

  <property name="hello_jar" value="hello.jar" />

  <property name="name" value="HelloWorld" />

  <property name="version" value="1.0" />

  <property name="year" value="2010" />

  <echo message="----------- ${name} ${version} [${year}] ------------" />

  <target name="init">

  <echo message="mkdir ${dest}"></echo>

  <mkdir dir="${dest}" />

  </target>

  <target name="compile" depends="init" description="Compile Java code">

  <javac srcdir="${src}" destdir="${dest}" includeantruntime="on"/>

  </target>

  <target name="build" depends="compile">

  <jar jarfile="build/${hello_jar}" basedir="${dest}"/>

  </target>

  <target name="run" depends="build">

  <java classname="test.ant.HelloWorld" classpath="build/${hello_jar}"/>

  </target>

  <target name="clean">

  <delete dir="${dest}" />

  <delete file="${hello_jar}" />

  </target>

  </project>

运行:

  Buildfile: D:ant_homeapache-ant-1.8.1binbuild.xml

  [echo] ----------- HelloWorld 1.0 [2010] ------------

  init:

  [echo] mkdir build/classes

  compile:

  [javac] Compiling 1 source file to D:ant_homeapache-ant-1.8.1binbuildclasses

  build:

  [jar] Building jar: D:ant_homeapache-ant-1.8.1binbuildhello.jar

  run:

  [java] Hello World

  BUILD SUCCESSFUL

  Total time: 1 second

检查在目录D:ant_homeapache-ant-1.8.1binbuild下生成hello.jar

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。