Manage projects with Ant

zhaozj2021-02-08  385

Manage projects with Ant

content:

Ant Introduction

two. Ant installation and configuration

Three: Management projects with ANT

Four: Tips

This article describes the basic syntax of Ant and how it applies to the management of projects.

Ant Introduction

There may be many readers don't know what is Ant, and how to use it. But as long as you have used Linux, you should know what made, when we compile the Linux kernel and some software source program, we often need to enter Make under the console. Make is actually a project management tool, and the functions implemented by Ant are similar to MAKE. ANT is a subproject in the Jakarta project in the Apache Software Foundation, since Java is written, there is a good cross-platform. Ant consists of some built-in tasks (task) and alternative tasks (of course you can also write your own tasks), when you use Make, you need to write a Makefile file, and use Ant to write a build.xml file. Due to the use of XML syntax, the build.xml file is easy to write and maintain, and the structure is very clear, and it is unlike a Makefile file has so much restrictions (such as a space in front of the TAB symbol, the command will not be executed). Ant's advantage is far more than this, it is also easy to integrate into some development environments (such as Visual Age, JBuilder, NetBeans).

two. Ant installation and configuration

installation

Ant's current version is 1.3, first

Http://jakarta.apache.org/ant/index.html Download ANT Latest Version 1.3, extract to C: / Ant (Window Operating System) or / USR / local / Ant (Linux operating system), because we want to use XMLC, and Ant1.3 do not include it, so we need David.li to write XMLC tasks written by ANT. Specific URL

Http://www.digitalsesame.com/enhydra/enhydraant20001213.tar.gz. Replace Ant.jar in the downloaded file in Ant1.3 in ant.jar. This way Ant has changed to 1.2.

2. Set the path

(1): Windows98 operating system

Edit C: /enhydra/.bashrc, add the following three lines

Export Ant_Home = / Ant

Export java_home = / jdk-1.2.2

Export Path = $ {Path}: $ {ant_home} / bin

(2): Linux operating system

Edit / etc / profile or user directory, join the following three lines

Export Ant_Home = / usr / local / Ant

Export java_home = / usr / local / jdk-1.2.2

Export Path = $ {Path}: $ {ant_home} / bin

Three: Management projects with ANT

1: Basic file directory structure unzipped to any directory, we can see the directory tree structure

├-bin

├─DOCS

│ ├─ANT2

│ ├─API

│ │ └─ORG

│ │ └─apache

│ │ └─Tools

│ │ ├─ANT

│ │ │ ├─Taskdefs

│ │ │ │ ├─compilers

│ │ │ │ └─ ptional

│ │ │ │ ├─clearcase

│ │ │ │ ├─depend

│ │ │ │ │ └─ConstantPool

│ │ │ │ ├─DOTNET

│ │ │ │ ├ ej

│ │ │ │ ─IDE│ │ │ │ ├─JAVACC

│ │ │ │ ├─jlink

│ │ │ │ ├─JSP

│ │ │ │ ├─junit

│ │ │ │ ├─Metamata

│ │ │ │ ├─NET

│ │ │ │ ├ --Perforce

│ │ │ │ ├─SCM

│ │ │ │ ├─Sound

│ │ │ │ └─VSS

│ │ │ ├─Types

│ │ │ └─UTIL

│ │ │ └─Regexp

│ │ ├─mail

│ │ └ -TAR

│ └ -Manual

│ ├─coretasks

│ ├─coretypes

│ ├ inTegration

│ └─OptionalTasks

└ -LIB

In this directory tree structure, different from traditional items is that we replace makefile with build.xml. Before telling this build.xml file, we know the structure of a basic build.xml file.

2: Basic writing specification for build.xml

Below we will tell the writing method of this file, below is the full content of this file

1.

2.

4.

5.

6.

7.

For convenience, we add a line number for each line, the first line is the basic element of the XML file, the second line shows that this is a project, the end of the chain, in the second line, Name = "MyProject "Note the name of this project, this property can be available. Basedir = "." Describes the basic directory, this property can be available. DEFAULT = "dist" describes what the default target of the project is, this property must be. The Target is a collection of a series of tasks (TASK). The writing method of each task (task) is as follows:

The third line defines some properties to be used later, which is very similar to the global variable defined in the program. From the fourth line start definition target (target), Name = "init" indicates the name of this target, and the Name property must have some time when defining the target. Other properties can be selected, such as Depends, Unless, specific Please refer to the ANT documentation. The fifth row begins to define the tasks within this target, where MKDir is the internal task name, Dir is the properties of this task, which is $ {dist}. This task is to create a directory. Where $ {dist} is a value for obtaining the DIST property (that is, we define the third line). The above is a basic build.xml file. You can enter ant -buildfile build.xml on the command line

Look at whether there is a DIST directory in your current directory. If an error, it may be that you didn't configure the Ant, see the installation and configuration in the previous, see where it is wrong. 3: Build.xml file

The build.xml file is as follows, where there is any comments and unrelated code deleted, and make a small change

1:

2:

3:

4:

5:

6:

7:

8:

9:

10:

11:

12:

13:

14:

15:

16:

17:

18:

19:

20:

21:

22:

23:

24:

25:

26:

27:

28:

29:

30:

31: 32:

33:

34:

35:

36:

37:

38:

39:

40:

41:

42:

43: 44:

45:

46:

47: Sourceout = "$ {build.xmlc.dir}"

48: INCLUDES = "** / *. Html">

49:

50:

51:

52:

53:

54:

55:

56:

57:

58:

59:

60:

61:

62: 63:

64:

65:

66:

67: destDir = "$ {build.classes}"

68: classpathref = "build.classpath"

69: Debug = "$ {build.debug}" />

70:

71:

72: destdir = "$ {build.classes}"

73: classpathref = "build.classpath"

74: Debug = "$ {build.debug}"

75: Includes = "$ {app.name} / **"

76: />

77:

78:

79:

80: 81:

82:

83:

85:

86:

87:

88:

89:

90:

91:

92:

93:

94:

95: 96:

97:

98:

99:

100:

101:

102:

103:

104:

105:

106:

107:

108: TOFILE = "$ {build.dir} /multiServer.conf"

109: filtering = "on" />

110:

111:

112:

113: 114:

4: Build.xml Detailed Description

Below we will tell this document in detail, in order to facilitate, I added the line number, of course, some basic things I will no longer be repeated. The fourth line TASKDEF task (task belongs to the internal task of Ant, which is to define a task, and its basic attribute has Name, ClassName, which is required when defined. The eighth row begins to define a path, it has a property ID, and the value of this ID we can reference this PATH, see Chapter 68. Target INIT (from 14 lines to 34 lines) defines some basic attributes, mainly for use in the back Target. On page 38, you will see Depends = "init", Depends is the optional attribute when defining a target, which means that this goal will not be executed if the init target is not executed (error or other reason).

Define the XMLC task from line 46, end, in line 58, there are many parameters in the middle, and srcdir specifies the source file directory, Sourceout specifies the output directory, including all HTML files in the source file directory included all HTML files in the source file directory. * Is a wildcard.

Indicates the cancel warning, means simultaneous interface and implementation code, for example: a Welcome.html, it will generate two files: WelcomeHtmlimpl.java, WelcomeHTML. Java, WelcomeHtml.java only defines a interface WelcomeHTML, real implementation in WelcomeHtmlImpl.java. represents the encoding, because XMLC compiles the HTML file into the Java class, even if you have set the encoding in the HTML file, there will be no effect in the Java class, you must set the encoding at compile time . These two sentences are equivalent to enter -ssi -keep on the command line. The SSI parameter is included in the SSI file that defines the defined HTML file. See the Welcome2.html source code under the HTML directory: . The Keep parameter retains the Java file generated after compiling the HTML file. Chapter 57 is to rename the package. Because the HTML file is in the ANTMO / Presentation / HTML directory, the resulting Java class belongs to the ANTDEMO.Presentation.html package, and the value of our NEW will be changed to the new class. When using XMLC, the above parameters are generally enough. For more parameters, see the source code defined by XMLC Task.

From Chapter 63 to 77, the target (TARGET) defines the details of the compile, compiling the two parts, compiles the Java classes generated by XMLC, and the Java class in the project (the code in the business layer, the data layer) ). During this task, the srcdir property specifies the Java file storage location. The DESTDIR property specifies the compiled class file storage location, the classpathref property specifies the classpath, debug property settings Off or open debugging information, the incrudes property sets a filter, which specifies the compilation of those files Otherwise, Javac will compile all Java files in the directory specified by the SRCDIR property. 81 lines to 91 lines begin to copy other files used in the program to the target directory so that the next step is packaged. In the COPY task, the Todir property specifies the target directory, as for those files, specified by the nested FileSet task in the COPY task. In FileSet, DIR specifies that the basic directory, the include, and Exclude properties are used to filter files, and the qualified files will be copied to the target directory.

95 lines to 98 rows began to package the program, the JARFILE property specifies the packaged file name, basedir specifies the basic directory, the files and subdirectories in the basic directory are placed in the JAR file in the JAR file.

102 lines to 113 lines, start copying profiles, configuration files include antdemo.conf, multiserver.conf, start. Where is the 112nd line, the chmod task changes the properties of the Start file to anyone can perform and readable.

Through the above explanation, you may see the superiority of Ant, Ant can easily manage a large project, of course, other projects can be, it is important that you can easily expand its Task. I believe that more and more people will use Ant to manage project management.

4: Tips:

Since it may be wrong because the screen is used, the screen is not big enough, it may be clear, it is best to put the compilation error information into a file, as follows, using Ant:

ANT -BUILDFILE BUILD.XML -LOGFILE Error.log

The error message will be placed in error.log, because the XML file name is not necessarily when using the buildfile parameter, it can be any XML file, such as Project.xml.

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

New Post(0)