Java ant configuration and build project graphics tutorial

  • 2020-04-01 02:14:09
  • OfStack

Ant is a java-based build tool. Ant files are XML files that configure the build target process, also known as Ant scripts.
(because I don't know much about this, the wording may be deviated from my personal understanding, thank you for pointing out)

How do I configure the Ant tools? The following steps are described:
1.   Download a Java ant development tool and unzip it to the appropriate disk       For example: apache-ant-1.8.2-bin.tar.zip; Uploaded resources

2. Open the command line, start -- run -- CMD -- enter, and type ant, which will prompt that this is not an internal file. This is where the part 3 configuration environment is used

3. Right click on my computer -- point attribute -- advanced system configuration -- environment variable -- new environment variable, as shown in the figure:

    < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260843352.jpg ">

4. Start configuring 3 variables; (ANT_HOME; JAVA_HOME. The 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)

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260843353.jpg ">

4-2. Variables :(JAVA_HOME)   Value: (C:\Program Files\Java\jdk1.6.0_10)

  < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260843354.jpg ">

4-3. Variable :(path) & cake;   Value (% % PATH; %ANT_HOME%/bin) as shown:

  < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260843355.jpg ">

5. After the environment configuration is finished, we can go back to the second part to continue. Enter ant and press enter. As shown in figure:

            < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/20130825112857859.jpg ">

After the tool configuration is ready to write our Java program, the following steps:

1. Create a new project with eclipse, and take mine as an example: my project name is: 2013-08-25-ant.
There is a class code written in the following figure:

    < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/20130825113611734.jpg ">

Create a new build.xml&cake directory at the root of the project. File, as shown:

  < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260843356.jpg ">

3. The code in build.xml is:

<?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 blank line at the bottom indicates that the project can be found, otherwise the path cannot be found.      
As shown in the picture:

        < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/20130825114643718.jpg ">

5. Continue with ant and it will prompt you to find the build.xml file in your Java project. And help you build the project, as shown below:

  < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/20130825115040609.jpg ">

  If you look at your projects and directories, you will find two more folders, which means you have successfully built your project

  < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/20130825115244734.jpg ">


Related articles: