Ant download and deployment

Source: Internet
Author: User
Tags gz file

Http://ant.apache.org/bindownload.cgi for Apache ant 1.7.0 is the best available version

Deployment:

Refer to java_home deployment

 

 

======================================

Test ant installation successful.

 

 

The following uses helloworld as an example to describe how to use helloworld.
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/
Download the ZIP file in Windows
Download the tar.gz file in UNIX

. Install JDK:
Install C:/JDK and check whether C:/JDK/bin/Java is available.

. Install ant:
Decompress ant to the local hard drive C:/ant and confirm that C:/ANT/bin/ant. bat can be found.

. Set environment variables:
Jdk_home: C:/JDK
Ant_home: C:/ant
Path: Add C:/ANT/bin; C:/JDK/bin to the beginning of the original path.
Note:
In Windows, choose my computer> Properties> advanced> environment variables> User variables.
Each time the environment variable is modified, You have to reopen the MS-DOS window to take effect

. Start development:

The directory structure of an ant project:
C:/helloworld: main directory of the project
/Src: source program directory
/Classes: directory of the compiled class file
/Lib: the class library directory required by the development project, such as the JDBC lib required for database development (this time it is not used)
/Jar: the packaged jar program directory (not used this time)
/Build. xml: project configuration file

1. Create a project's main directory
Mkdir C:/helloworld

2. Create a project configuration file:

C:/helloworld/builder. xml
-----------------------------------------------------------------------------
<? XML version = "1.0"?>

<Project default = "build" basedir = ".">

<Property name = "appname" value = "helloworld"/>
<Property name = "base" value = "."/>
<Property name = "src" value = "src"/>
<Property name = "build" value = "classes"/>
<Property name = "myclasspath" value = "$ {build}"/>

<Target name = "build">
<Mkdir dir = "$ {build}"/>
<Javac classpath = "$ {myclasspath}" srcdir = "$ {SRC}" destdir = "$ {build}">
<Include name = "**/*. Java"/>
</Javac>
</Target>

<Target name = "run" depends = "build">
<Exec executable = "Java">
<Arg line = "-classpath $ {myclasspath} helloworld"/>
</Exec>
</Target>

<Target name = "clean">
<Delete multiple deemptydirs = "true">
<Fileset dir = "$ {build}"/>
</Delete>
</Target>

</Project>
-----------------------------------------------------------------------------

3. Create the source code directory and put all Java programs in it.
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
Note:
Call target build in builder. xml
Helloworld. Class appears in C:/helloworld/classes.
This command will compile all java files (including subdirectories) 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
Call target run in builder. xml
Note that the depends = "build" after target run can be called only after the build is successful.

7. Clear the class file:
C:/helloworld> ant clean
Buildfile: Build. xml

Clean:
[Delete] deleting 1 files from C:/helloworld/classes
[Delete] deleted 1 directory from C:/helloworld/classes

Build successful
Total time: 2 seconds

Benefits of ant:
1. Compared with other project management tools, there is only one text configuration file build. XML, which is easy to configure.
2. simple command, ant run, ant clean...
3. The installation is simple and consumes less resources. As long as JDK is installed, ant can run

Using Ant for Java program development has become a consensus in the Java field.
On this basis, you can build more complex projects
We will continue with the introduction in the future:
Use ant to develop database projects
Use ant to develop Web Applications
Use ant and CVS to develop multi-person projects and manage project versions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.