Use ant to package war files

Source: Internet
Author: User

The most silent problem occurs. There are various compilation methods in java, including specialized compilation tools from ide, maven, and ant. Ant is very famous. This time we met such a project to be deployed, but the built-in build file is not usable. First, we considered how to use ant in Myeclipse, you just need to set it in the project. Remember to remove the java builder option.

Although it has been correctly set and built, but it does not have a normal compilation, let's look at build. xml. Although I understand both English and content, I am not clear about its principles. I cannot directly find some war-packed builds on the Internet. It seems that there is no way, so I have to carefully learn the ant script.

In fact, ant is a make tool, while build. xml is a makefile. Xml is used, which is easier to write than makefile in c and more powerful.

Code
<? Xml version = "1.0" encoding = "UTF-8"?>
<! -- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
Directory with the processing instruction <? Eclipse. ant. import?>
As the first entry and export the buildfile again. -->
<Project basedir = "." default = "build" name = "project name">
<Property environment = "env"/>
<Property name = "ECLIPSE_HOME" value = "D:/Program Files/MyEclipse 6.5/eclipse"/>
<Property name = "debuglevel" value = "source, lines, vars"/>

<Property name = "target" value = "1.5"/>
<Property name = "source" value = "1.5"/>

<Target name = "init">
<Property name = "build" value = "build"> </property>
<Property name = "src" value = "src"> </property>
<Mkdir dir = "$ {build}"/>
<Mkdir dir = "$ {build} \ WEB-INF"/>
<Mkdir dir = "$ {build} \ WEB-INF \ classes"/>
<Copy todir = "$ {build}">
<Fileset dir = "$ {basedir} \ WebContent">

<Include name = "WEB-INF/**"/>
<Include name = "*. jsp"/>
<Include name = "conf/**"/>
<Include name = "ext/**"/>
<Include name = "fusioncharts/**"/>
<Include name = "images/**"/>
<Include name = "jsp/**"/>
<Include name = "META-INF/**"/>
<Include name = "style/**"/>
<Include name = "temp/**"/>
</Fileset>
</Copy>
</Target>
<Target name = "complie" depends = "init">
<Javac srcdir = "$ {src}" destdir = "$ {build}/WEB-INF/classes">
</Javac>

</Target>
<Target name = "makewar" depends = "complie">
<War warfile = "$ {build}/test. war" webxml = "$ {build}/WEB-INF/web. xml">
<Lib dir = "$ {build}/WEB-INF/lib"/>
<Classes dir = "$ {build}/WEB-INF/classes"/>
<Fileset dir = "$ {build}"/>
</War>

</Target>

</Project>

The above build is briefly written. xml, in fact, the three targets are all dependent on each other, but to execute them, add a parameter, and the parameter is the name in the target. Set it in the project, in this way, the war file can be normally packaged. The key is to be familiar with the actual project and know the content to be packaged.

Conclusion: Although ant has not been used to write a brilliant build script, it can be found that it is unreliable to find many items that are readily available, especially if you have not understood the principle, it will only waste more time.

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.