The original text is easy to understand and has little content. It is recommended to read English directly. Here is a simple translation for future reference.
In this example, I use the Spring SimpleFormController example to explain the war construction process, as shown in the structure of the application.
All classes in src need to be compiled and placed under the build/classes directory. The war package to be built must be placed in the dist directory.
Therefore, the first step is to create the build/classes and dist directories and use init to complete these tasks:
[Html]
<Target name = "init">
<Mkdir dir = "build/classes"/>
<Mkdir dir = "dist"/>
</Target>
Next, compile the class in the src directory to the build/classes directory. Before compiling, set classpath as follows:
[Html]
<Path id = "compile. classpath">
<Fileset dir = "WebContent/WEB-INF/lib">
<Include name = "*. jar"/>
</Fileset>
</Path>
Next, compile with the javac command. Make sure that the relevant directories have been created during compilation. Therefore, the compilation depends on init, as shown below:
[Html]
<Target name = "compile" depends = "init">
<Javac destdir = "build/classes" debug = "true" srcdir = "src">
<Classpath refid = "compile. classpath"/>
</Javac>
</Target>
Next, you can create a war package and use the war Command provided by ant to complete this work:
[Html]
<Target name = "war" depends = "compile">
<War destfile = "dist/AntExample. war" webxml = "WebContent/WEB-INF/web. xml">
<Fileset dir = "WebContent"/>
<Lib dir = "webcontents/WEB-INF/lib"/>
<Classes dir = "build/classes"/>
</War>
</Target>
War Command details reference: http://ant.apache.org/manual/Tasks/war.html
Finally, some cleanup work may be required, such:
[Html]
<Target name = "clean">
<Delete dir = "dist"/>
<Delete dir = "build"/>
</Target>
The following is a complete build script:
[Html]
<? Xml version = "1.0"?>
<Project name = "AntExample1" default = "war">
<Path id = "compile. classpath">
<Fileset dir = "WebContent/WEB-INF/lib">
<Include name = "*. jar"/>
</Fileset>
</Path>
<Target name = "init">
<Mkdir dir = "build/classes"/>
<Mkdir dir = "dist"/>
</Target>
<Target name = "compile" depends = "init">
<Javac destdir = "build/classes" debug = "true" srcdir = "src">
<Classpath refid = "compile. classpath"/>
</Javac>
</Target>
<Target name = "war" depends = "compile">
<War destfile = "dist/AntExample. war" webxml = "WebContent/WEB-INF/web. xml">
<Fileset dir = "WebContent"/>
<Lib dir = "webcontents/WEB-INF/lib"/>
<Classes dir = "build/classes"/>
</War>
</Target>
<Target name = "clean">
<Delete dir = "dist"/>
<Delete dir = "build"/>
</Target>
</Project>
If there are attachments, I cannot find the place where the attachments are to be uploaded. I am not familiar with the related operations. Click the original file to download the attachment.