Skip to content

Instantly share code, notes, and snippets.

@coseos
Created April 15, 2015 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coseos/aef90e35c51d77f83ed6 to your computer and use it in GitHub Desktop.
Save coseos/aef90e35c51d77f83ed6 to your computer and use it in GitHub Desktop.
Create a snapshot of a web application with warShot to a .war file
<?xml version="1.0" encoding="UTF-8"?>
<project name="warShot" default="warShot" basedir="..">
<!--
Copyright (c) 2014-2015
coseos / K2IT Gesellschaft fuer Informationstechnik mbH
Thorsten Lorenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
-->
<basename property="build.name" file="${basedir}"/>
<property name="webinf.dir" value="WEB-INF"/>
<property name="build.dir" value="${basedir}/${webinf.dir}/build"/>
<property name="war.file" value="${build.name}.war"/>
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd'T'hh:mm:00" />
</tstamp>
<buildnumber file="${basedir}/${webinf.dir}/build.number"/>
<fileset id="content.fileset" dir="${basedir}">
<include name="**/*.html"/>
<include name="**/*.css"/>
<include name="**/*.js"/>
<include name="**/*.json"/>
<include name="**/*.jsp"/>
<include name="**/*.png"/>
<include name="**/*.pdf"/>
</fileset>
<target name="warShot">
<war destfile="${build.dir}/${war.file}" webxml="${webinf.dir}/web.xml">
<fileset refid="content.fileset"/>
<lib dir="${basedir}/${webinf.dir}/lib"/>
<zipfileset dir="${basedir}/${webinf.dir}/classes" prefix="${webinf.dir}/classes"/>
<manifest>
<section name="${build.name}-${build.time}-b${build.number}">
<attribute name="Built-With" value="warShot"/>
</section>
<attribute name="Built-By" value="${user.name}"/>
</manifest>
</war>
</target>
</project>
@coseos
Copy link
Author

coseos commented Apr 15, 2015

warShot

Forget about fat and clumsy web-application distribution and deployment. Things can be really easy.
Take your development environment and make a snapshot once your tests are ok. This will give you a working web-application. Why rebuild at night? I can't wait 24 hours. This little ant-build file is all you need.

Use warShot.xml with ant to build a snapshot of your web application

mini-HowTo

Place this file in your web-app's WEB-INF folder and run ant on your web-app.

ant -f WEB-INF/build.xml

warShot will create a .war file with the name of the web-app (taken from the folder where the web-app is located, e.g. for a root web-app this is "ROOT.war").

content.fileset

Modify this fileset to reflect your project. The most common file types are already included.

Production ready

I use this script in production environment with success for some time now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment