Constructing a war file...

This question is more about the Eclipse environment that Vaadin, but I’m not getting any help from the Eclipse site - perhaps someone here can enlighten me…

I use Eclipse to build my system - and I am now looking at automating my project builds. For jar files, this is fairly straightforward - Eclipse will export the ant scripts needed to compile and build my jars. But I can’t figure out any way to construct a .war file for my web applications from the command line (ie. without using Eclipse). Anyone have any idea how I can do that easily?

If I compile my source code, everything that goes in the .war file appears to be in the build directory except for libraries which are listed in the classpath - any way to force those into the build area so I could manually package them? I don’t want to hand craft scripts for each program - I’d like to have this handled automatically if possible.

Thanks very much,

nbc

This is a good question. I’ve been planning to write a section about this, but haven’t done it yet. There’s some big unsolved issues, mainly how to package only production libraries in the WAR, because the current Ivy dependencies do not allow such configuration. Also, production mode would have to be enabled for the servlets when running from the WAR package.

You could see the
build.xml
for the book-examples, especially the [tt]
package-war
[/tt] target. Note that the compilation targets (server-side, client-side, and theme) might not even work currently, I’m not using them at the moment - the theme is an old CSS theme and the server-side classes and the widget set is compiled in Eclipse, and the packaging target just packages them. It’s worth noting the [tt]
resolve
[/tt] target that downloads the libraries (note that it does not clean the libraries folder, you need run the [tt]
clean
[/tt] target manually if any of the libraries get newer versions, which means often).

I was able to get a kludge working for now. Basically, my pgm.xml file looks like this:


<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Build myPgm WAR file" basedir=".">
    <property name="warfile" value="/app/Programs/myPgm/dist/myPgm" />
    <target name="create">
        <war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
            <classes dir="build\classes" />
            <fileset dir="WebContent">
                <exclude name="WEB-INF/web.xml" />
            </fileset>
            <lib dir="../../../../../../lib/Git/EclipseLink" >
                <include name="eclipselink.jar" />
            </lib>
            <lib dir ="../pathtoanotherlibrary" />
                <include name="anotherlibrary.jar" />
            </lib>
                .... many more libraries, picked up by hand - would like to do this automatically !!
        </war>
    </target>
</project>

This, combined with the exported build.xml file lets me run:

ant clean
ant
ant -f pgm.xml create

and it actually constructs the war file. However any change in a library version, or update to a vaadin library will require manually editing this file. It would be nice if I could pick up the libraries from a classpath variable somehow… But I don’t know much about ant - I’m basically throwing stuff at the wall to see what sticks…

nbc

Your Eclipse project doesn’t use Ivy to resolve the Vaadin and other libraries? Is it a Vaadin 6 project?

No - it does use Ivy - it is a Vaadin 7 project

nbc