I needed to add content to the war directory/file that play generates via the “play war” command. The content varied from files added to the top level of the war (alongside WEB-INF) to customising WEB-INF/web.xml. Checking the core documentation, no support for this is mentioned. Checking the python scripts that come with play!, I found a snippet of hope:

    if os.path.exists(os.path.join(app.path, 'war')):
        copy_directory(os.path.join(app.path, 'war'), war_path)

A basic play app has the structure


If you add a directory called “war” at the same level as app, conf, etc, this will be used as the basis of the generated war. So,

	|   |-deployment.properties

will add the deployment directory alongside the WEB-INF folder, and the default web.xml supplied by play! will be replaced by the one you provide. arbitrary.txt will also be placed in WEB-INF.

Make sure sure that, if you replace web.xml, you keep all content found in $PLAY_HOME/resources/war/web.xml otherwise your webapp will not start properly! So, your custom web.xml might look like

<?xml version="1.0" ?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        <!-- START: standard play content -->
        <display-name>Play! (%APPLICATION_NAME%)</display-name>

        <!-- END: standard play content -->

	<!-- START: custom content -->
	<!-- END: custom content -->

Note the use of fields denoted by % to enable play to update the content.

(As usual, once this was done I later found a mention in the optional GAE module – http://www.playframework.org/modules/gae-1.1/home)

2 thoughts on “quick&easy: Automatically add content to play!-generated war files

  1. I’m not english fluent, by I think there is a typo error :

    the default web.xml supplied be play!
    should be :
    the default web.xml supplied by play!


    PS: And perhaps Play! (not play!) 😉

  2. be -> by…corrected.

    play! -> Play!…I’ve generally stopped using the correct capitalisation for things due to laziness 🙂

    Thanks for the correction!

Leave a Reply

Your email address will not be published. Required fields are marked *