Pay tribute to ants (1)

xiaoxiao2021-03-06  15

Residual to the ant

Author: 9cbs Dorian wrote on 2004-03-16

What is this article?

This article describes how to use Ant this very powerful technology to deploy and components a Java application. Examples of ANT in ductility are elaborated by a HelloWorld example. Ant complements the integrated development environment, but does not replace any integrated development environment, and no integrated development environment can replace Ant. Ant provides a component-based-deployment process to reduce potential damage. ANT makes the automation components and tests of the program possible.

Where to get Ant as part of the Jakarta project, ANT is developed by Apache Software. You can get our latest version at http://jakarta.apache.org/ant/index.heml. After downloading, decompressed to a directory (I am g: / program / Ant), and set the environment variable as follows: set ant_home = g: / program / antpath =% path%; g: / program / ant / bin

Before using Ant

Ant component file is written in XML language. Each component file contains a project element, each project element contains multiple target elements, while each target element also includes a series of task elements. A task element performs functions such as copy files, compiling a project or established a JAR file.

You can use the Depends property to declare a target dependent on another goal. Let us look at a simple example (list one).

Listing 1:

When you enter Ant in the current directory, it looks for component files called Build.xml. It performs the default target in the component file (Defaule = "Compile"). Task Javac built in the Compile target to compile the Java original code under the current directory. And compile content in the SRC directory under the Classes in the current directory. It should be noted that there is a Depends property in this goal to point to the Prepare target (Depends = "preted"), so the prepare target will be executed before executing the Compile target.

Here is just to briefly introduce Ant's usage, and a ANT guide written by Steve Loughran is called Ant in anger. It can be found in the DOCS directory in the binary release package of Ant.

Start

It is necessary to introduce this project before the beginning of the directory structure (G: / Program / Ant), as shown in Figure 1.

Figure one

You can see that three Java source files are stored in PanelàSrcàdorian, FrameàSrcàdorian, FrameàSrcàdorian in the HelloWorld project directory. Its source files are like a list.

Listing 2;

//HelloWorldPanel.javapackage Dorian; import java.awt.BorderLayout; import java.awt.Font; import javax.swing.JPanel; import javax.swing.JLabel; public class HelloWorldPanel extends JPanel {public HelloWorldPanel () {setLayout (new BorderLayout ()); Label = new Jlabel ("Hello World!"); Label.SetAlignmentX (jlabel.center_alignment); label.setalignmenty (jlabel.center_alignment); font font = new font ("Arial", Font.Bold, 20) ; label.setFont (font); add (label, BorderLayout.CENTER);} private JLabel label;} // HelloWorldFrame.javapackage Dorian; import javax.swing.JFrame; import java.awt.Container; public class HelloWorldFrame extends JFrame { Public helloworldframe () {Panel = new helloworldPanel (); contentpane = this.getContentPane (); ContentPane.Add (Panel); this.SetTitle ("Hello World!"); this.setsize (width, height); this.dispose (); This.setdef aultCloseOperation (JFrame.EXIT_ON_CLOSE);} private Container contentPane; private HelloWorldPanel panel; private final static int WIDTH = 200; private final static int HEIGHT = 100;} // HelloWorldMain.javapackage Dorian; public class HelloWorldMain {public static void main (String [] args) {helloworldFrame Frame = new helloworldframe (); frame.setvisible (true);}} I will not say that I will not say that the code in the list is the simplest example in the Java application. Then, you will have a directory structure for the PANEL (List 3). The Panel component file has 6 goals: SetProps, Init, Clean, Delete, Prepare, Compile, Package, ALL.

转载请注明原文地址:https://www.9cbs.com/read-46460.html

New Post(0)