码迷,mamicode.com
首页 > 其他好文 > 详细

Ant教程

时间:2016-04-24 23:07:01      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

安装ant,去http://ant.apache.org下载

配置环境变量(前提是配置了java环境变量)

ANT_HOME

G:\Software\ant1.9.7   //ant根目录

PATH后添加 

;%ANT_HOME%\bin            //注意分号

 

cmd命令输入ant,结果为

Buildfile: build.xml does not exist!
Build failed

表示安装成功

  

测试程序helloWorld

package test;

public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("HelloWorld");
	}

}

src目录下新建build.xml  

<?xml version="1.0" ?> 

<project name ="itProject" default="compile" basedir=".">
	<target name="clean">
		<delete dir="${basedir}/build"/>
	</target>
<target name="compile" depends="clean">
		<mkdir dir="${basedir}/build/classes"/>
<javac srcdir="${basedir}" destdir="${basedir}/build/classes" includeAntRuntime="false"/>
</target>
	<target name="jar">
	        <mkdir dir="build/jar"/>
	        <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
	            <manifest>
	                <attribute name="Main-Class" value="test.HelloWorld"/>
	            </manifest>
	        </jar>
	    </target>

	    <target name="run">
	        <java jar="build/jar/HelloWorld.jar" fork="true"/>
	    </target>
</project>

run as ant build结果为

Buildfile: G:\workspace\itProject\src\build.xml
clean:
clean:
compile:
    [mkdir] Created dir: G:\workspace\itProject\src\build\classes
    [javac] Compiling 1 source file to G:\workspace\itProject\src\build\classes
jar:
    [mkdir] Created dir: G:\workspace\itProject\src\build\jar
      [jar] Building jar: G:\workspace\itProject\src\build\jar\HelloWorld.jar
run:
     [java] HelloWorld
BUILD SUCCESSFUL
Total time: 1 second

表示build成功

以上是web项目当中,可以直接build,但是我发现在java普通项目中需要分开运行,就是先clean compile再jar run

  

 

Ant教程

标签:

原文地址:http://www.cnblogs.com/JAYIT/p/5428644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!