Develop Java programs using ANT
Often listen to you, which Java development tool is better, JBuilder, Virtual Cafe?
Today introduced a simple easy-to-use Java development, compile, integration, test tool: JAKARTA ANT
He is known as Make in the Java environment (Make all knows in the development of C procedures)
Java program editor loves to use 啥, I like to use UltraEdit.
Take HelloWorld as an example to introduce his use.
This example can be downloaded here:
ftp://cinc.dns2go.com/pub/doc/code/ant/helloWorld.zip
Download Ant: (latest version 1.5)
http://jakarta.apache.org/builds/jakarta-ant/release/v1.5/bin/
Under Windows, please download the ZIP file
Unix please ask the tar.gz file
Install JDK:
Install to C: / JDK, and confirm that you can find C: / JDK / BIN / JAVA
Install ANT:
Unzip ANT to the local hard drive C: / AT, and confirm that you can find C: /nt/bin/ant.bat
Set an environment variable:
JDK_HOME: C: / JDK
Ant_home: C: / Ant
PATH: At the beginning of the original Path plus C: / Ant / bin; C: / JDK / BIN
Note:
Windows doing action: My Computer -> Properties -> Advanced -> Environment Variables -> User Variables
Each time you modify the environment variable, reopen the MS-DOS window to take effect.
Start development:
A ANT project directory structure:
C: / helloworld: project main catalog
/ src: Source program directory
/ classes: Compiled Class file directory
/ lib: The class library directory required to develop the project, such as the JDBC LIB (this time it is useless) when developing the database.
/ jar: Packing a good JAR program directory (this time it is useless)
/BUILD.XML: Project profile
1. Create a primary directory of a project
MKDIR C: / HelloWorld
2. Create a project profile:
C: /helloworld/builder.xml
-------------------------------------------------- ---------------------------
XML Version = "1.0"?>
javac>
target>
exec>
target>
delete>
target>
provject>
-------------------------------------------------- ---------------------------
3. Create a source code directory, all Java programs are placed inside
MKDIR C: / HelloWorld / SRC
4. Create HelloWorld.java
C: /helloworld/src/helloWorld.java
-------------------------------------------------- ---------------------------
/ **
* Demo class for run helloworld by Ant
* /
Public class helloworld {
Public static void main (string args []) {
System.out.println ("Hello World!");
}
} // eoc
-------------------------------------------------- ---------------------------
5. Compile HelloWorld
C: / helloworld> Ant Build
Buildfile: build.xml
Build:
Build Successful
Total Time: 2 Seconds
Description:
Call Target Build in Builder.xml
HelloWorld.class will appear in C: / HelloWorld / Classes
This command compiles all Java files (including subdirectory) in the src directory.
6. Run HelloWorld
C: / helloworld> Ant Run
Buildfile: build.xml
Build:
Run:
[EXEC] Hello World!
Build Successful
Total Time: 2 Seconds
Target Run in Builder.xml
Pay attention to the depends = "build" after Target Run, only the builds can be called after running.
7. Clear the Class file:
C: / helloworld> Ant CleanBuildfile: build.xml
Clean:
[delete] deleding 1 Files from C: / HelloWorld / Classes
[delete] deleted 1 Directory from C: / HelloWorld / Classes
Build Successful
Total Time: 2 Seconds
Benefits using Ant:
1. With respect to other project management tools, there is only one text configuration file build.xml, configured simple
2. Simple command, one learn, Ant Run, Ant Clean ...
3. Simple installation, less resources, just install JDK, Ant can run
Develop Java program development with ANT has become a consensus of the Java boundaries.
On this basis, you can establish more complex projects.
Continue in the future:
Develop database project with ANT
Develop web application with ANT
Develop multiplayer projects with ANT and CVS and conduct project version management.
Recommended reading:
Apache Ant 1.5 Manual
Http://jakarta.apache.org/ant/manual/index.html
If there is time, you should read it, you can find a powerful function of many Ant.