ANT help develop the use of java projects
ANT is the Apache open source project, in the java development projects were widely adopted, a very powerful function! So we need to get to know this java-based tool.
ANT on the related presentations, please refer to www.apache.org.
First, we should install ANT from apache.org downloaded directly mounted on the machine can be used. Best settings related to the environment variable, although many systems can automatically identify. You should still set up ANT_HOME, JAVA_HOME, several PATH environment variable, such as ANT installed in your c: \ ant1.6 java installed in your c: \ j2sdk1.4.2. Then we can perform the following operations set environment variables ( winxp):
Set ANT_HOME = c: \ ant1.6
Set JAVA_HOME = c: \ j2sdk1.4.2
Set PATH =% PATH%% PATH% \ bin
Set up good command inside the ant after ant-enforcement version and see if it is the ant version can output information to confirm the successful installation
As many development tools are built-in ant, I direct eclipse as an example to demonstrate how the ant java development projects, where the project is very simple, a new project TestAnt, and then write src inside two categories as follows:
Package com.north;
/ **
* @ Author P2800
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
* /
Public class TestAnt
(
Public static void main (String [] args)
(
New MyWork (). Print ();
)
)
Package com.north;
/ *
* Created on 2004-7-23
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
* /
/ **
* @ Author P2800
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
* /
Public class MyWork
(
Public void print ()
(
System.out.println (System.getenv ( "CLASSPATH"));
)
)
I do not intend to introduce the use of excessive ant through the user's manual to see you soon-use. Build.xml but is directly related to the content and the content of some necessary explanations. Your new project TestAnt inside a file build.xml, this is the default ant to find the documents, if you use other file name so you should use ant-buildfile mybuildfile.xml
<project Default="jar" basedir="." name="myproject">
<description> This is my test for ant tool </ description>
<property Name="src" location="src"> </ property>
<property Name="dist" location="dist"> </ property>
<property Name="classes" location="classes"/>
<target Name="init">
<tstamp> </ Tstamp>
<mkdir Dir="${dist}"/>
<mkdir Dir="${classes}"/>
</ Target>
<target Name="compile" depends="init">
<javac Srcdir="${src}" destdir="${classes}"/>
</ Target>
<target Name="jar" depends="compile">
<jar Destfile="${dist}/myjar-${DSTAMP}.jar" basedir="${classes}"> </ jar>
</ Target>
</ Project>
This is not complicated build.xml his aim is to project inside the source code to compile and then packaged dist directory. Inside in the build.xml have the following main elements: project target task property. Which property is to allow you to define a number of attribute values, and in the subsequent task inside the target or to use. Each project must be designated a target to implement the default. Each target is the task set, to complete a specific task, the general complex than a single task. Target parameters depends a compiler described in the order, for example, where you want the implementation of the jar, must first compile implementation, and to compile prior to the implementation of init. Therefore, the order init-> compile-> jar. Is the most important task in a lot of built-in ant in the task, look at the list you will see that ant is very powerful. Which specific task you want to refer to his files.
Right choice selected build.xml run-> ant build, and you will see in the console
Buildfile: C: \ eclipse \ workspace \ TestAnt \ build.xml
Init:
[Mkdir] Created dir: C: \ eclipse \ workspace \ TestAnt \ dist
[Mkdir] Created dir: C: \ eclipse \ workspace \ TestAnt \ classes
Compile:
[Javac] Compiling 2 source files to C: \ eclipse \ workspace \ TestAnt \ classes
[Javac] Note: C: \ eclipse \ workspace \ TestAnt \ src \ com \ north \ MyWork.java uses or overrides a deprecated API.
[Javac] Note: Recompile with-deprecation for details.
Jar:
[Jar] Building jar: C: \ eclipse \ workspace \ TestAnt \ dist \ myjar-20040723.jar
BUILD SUCCESSFUL
Total time: 2 seconds
This means that the compiler success, but suggested that there is a deprecated API used in the proceedings, the readers to look for the manual to see how to show what API?








0 Comments to “ANT help develop the use of java projects”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.