Java Ant Configuration and construction project graphics and text tutorial _java

Source: Internet
Author: User
Tags mkdir

Ant is a Java-based build tool. An ant file is an XML file that configures the process of building a target, also known as an ant script.
(because this is not very understanding, so the use of words may be in the personal understanding of the deviation, thank you for pointing out)

How do I configure the Ant tool? The following step-by-step instructions:
1. Download a Java Ant development tool, extract to the appropriate disk such as version: Apache-ant-1.8.2-bin.tar.zip; uploaded resources

2. Open the command line, start---run----cmd-carriage return, and then enter Ant, it will be prompted to say this is not the word internal file. Use the third configuration environment

3. Right-click My Computer-point properties------Advanced System Configuration---Environment variables-new environment variables, as shown in the figure:



4. Start to configure 3 variables; (Ant_home;java_home;path)

4-1. Variable: (ant_home) Value: (C:\Program files\java\apache-ant-1.8.2-bin\apache-ant-1.8.2-bin\ apache-ant-1.8.2) is the path where you extract the ant file, as shown in figure:



4-2. Variable: (java_home) Value: (C:\Program files\java\jdk1.6.0_10) is the JAVA JDK installation path, as shown:



4-3. Variable: (path) value: (%path%;%ant_home%/bin) as shown:



5. After the environment is configured, we can go back to the second part of the continue, input ant to return, give you a hint to say that your build file does not exist, that proves that the environment configuration is not wrong. As shown in figure:



The tool is configured to write our Java program, and the following steps are followed:

1. Create a new project with Eclipse, name yourself, take my example: My project name is: 2013-08-25-ant.
It's written in a class code as shown here:

2. Create a new Build.xml file in the root directory of the project, as shown in figure:

The code inside the 3.build.xml is:
Copy Code code as follows:

<?xml version= "1.0"?>
<project name= "structured" default= "Archive" >
<target name= "Init" >
<mkdir dir= "Build/classes"/>
<mkdir dir= "Dist"/>
</target>
<target name= "Compile" depends= "init" >
<javac srcdir= "src" destdir= "build/classes"/>
</target>
<target name= "Archive" depends= "compile" >
<jar destfile= "Dist/project.jar"
Basedir= "Build/classes"/>
</target>
<target name= "clean" depends= "init" >
<delete dir= "Build"/>
<delete dir= "Dist"/>
</target>
</project>

4. Find my Java project from the command line, the bottom blank line indicates that the project can be found, otherwise the hint cannot find the path
As shown in the figure:

5. Continue typing ant, it prompts to find the Build.xml file inside the Java project. and help you build this project, as shown in the following figure:

6. View your project and directory you will find more than two folders, which means you have successfully built your project

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.