CruiseControl uses Ant to package Web projects into War

Source: Internet
Author: User

CruiseControl itself does not have the packaging project function, and its core is very small, but the strength of CruiseControl lies in its powerful scalability, especially when integrated with Ant.

To package a Web project into a WAR, you must use Ant.

1. First, we will write an Ant script to build it with the continuously integrated configuration file. xml is separated. Here I separate the Ant packaging function into a configuration file named "publisher. xml ".

The pubilsher. xml script is very simple. For more information about the script and its functions, see the source code:

<Project name = "RBAC" default = "war" basedir = ".">
<Property name = "classes" value = "build/classes"/>
<Property name = "build" value = "build"/>
<Property name = "lib" value = "WebContent/WEB-INF/lib/"/>

<! -- Path of the third-party jar package on which the project depends -->
<Path id = "lib_classpath">
<Fileset dir = "WebContent/WEB-INF/lib/">
<Include name = "*. jar"/>
</Fileset>
</Path>

<Target name = "clean" description = "delete build">
<Delete dir = "build"/>
</Target>

<Target name = "compile" depends = "clean" description = "Create a $ {classes} path and compile the class file to the $ {classes} path">
<Mkdir dir = "$ {classes}"/>
<! -- Execute Compilation -->
<Javac srcdir = "src" destdir = "$ {classes}">
<Classpath refid = "lib_classpath"/> <! -- Introduce third-party jar packages dependent on the project -->
</Javac>
</Target>

<Target name = "prepare" description = "copy configuration files such as Struts, Spring, Hibernate, and properties to the $ {classes} path">
<! -- Copy all xml configuration files -->
<Copy todir = "$ {classes}">
<Fileset dir = "src">
<Include name = "**/*. xml"/>
</Fileset>
</Copy>
<! -- Copy all attribute files -->
<Copy todir = "$ {classes}">
<Fileset dir = "src">
<Include name = "**/*. properties"/>
</Fileset>
</Copy>
</Target>

<Target name = "war" depends = "compile, prepare" description = "package war">
<War destfile = "$ {build}/RBAC. war" webxml = "WebContent/WEB-INF/web. xml">
<! -- Copy two folders under WebContent except Web-INF and META-INF -->
<Fileset dir = "WebContent" includes = "**/*. jsp"/>
<! -- Copy the jar package under the lib directory -->
<Lib dir = "$ {lib}"/>
<! -- Copy the class file under $ {classes} -->
<Classes dir = "$ {classes}"/>
</War>
</Target>
</Project>

This script is really simple!

Note: The dependent Jar package is very important. If your project introduces a third-party Jar package, such as: annotations-api.jar, please be sure to introduce it, otherwise the compilation will fail.

2. After the Ant script is compiled, how can we make the Ant script run properly?

Our idea is: after the CC build project is successful, the project will be packaged into a War, then we need to use CC to control the running of this script.

Anyone familiar with CC knows that CC has a very important element (element) --- <publishers>. Publishers runs after build is complete, CC builds run successfully or fail. If you want the Ant script to run successfully after the CC build is executed, you can find a sub-element <onsuccess/>, which means to execute this code segment after the build is successful. Then we can write the code:

<publishers>
<onsuccess>
</onsuccess>
</publishers>

Then, we add the code that calls the Ant script in <onsuccess>, as follows:

<antpublisher anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/publisher.xml"/>

The complete script is as follows:

<publishers>
<onsuccess>
<antpublisher anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/publisher.xml"/>
</onsuccess>
</publishers>

In this way, our Ant script can be executed, open your CC, wait for the first successful build, you will find that your project/directory has an additional build folder, the folder class is the compiled result.

Note: CC code can also be replaced by the following code:

<publishers>
<antpublisher anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/publisher.xml" thisbuildsuccessful="true"/>
</publishers>

Notice: I am a newbie. The code is poor. Please use Hai Han.

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.