Ant HelloWorld

阅读更多

开始学习一下ANT,在网上查了些资料,走出HELLOWORLD第一步

一.配置JDK,ANT:

 

JDK6
ANT1.8.2
系统环境变量配置:
JAVA_HOME:D:\jdk1.6.0_10
PATH:%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin
CLASSPATH:.;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar (要加.表示当前路径)
ANT_HOME:E:\apache-ant-1.8.2
PATH:%ANT_HOME%\bin; %ANT_HOME%\lib
打开CMD,输入java -version,输入ant,有相关提示说明配置成功
二、HELLOWORLD
1.新建src文件夹,在其中放入HelloWorld.java文件,内容如下:
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello world");
}
}
2.在src同级目录下放入build.xml文件,注意要保存成UTF-8格式。内容如下:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3.打开CMD,进入工程目录,输入ant(执行默认目标)或ant -file build.xml即可编译
E:\JavaWorkSpace\HelloWorld>ant -file build.xml
Buildfile: E:\JavaWorkSpace\HelloWorld\build.xml

init:
    [mkdir] Created dir: E:\JavaWorkSpace\HelloWorld\classes

compile:
    [javac] E:\JavaWorkSpace\HelloWorld\build.xml:15: warning: 'includeantruntim
e' was not set, defaulting to build.sysclasspath=last; set to false for repeatab
le builds
    [javac] Compiling 1 source file to E:\JavaWorkSpace\HelloWorld\classes

build:
      [jar] Building jar: E:\JavaWorkSpace\HelloWorld\hello.jar

run:
     [java] Hello world

BUILD SUCCESSFUL
Total time: 4 seconds
4.输入ant clean即可清除编译

你可能感兴趣的:(Ant HelloWorld)