About software development for the enterprise. Focus on Java EE and more general Java platforms.
You'll read a lot about Conferences, Java User Groups, Java EE, Integration, AS7, WildFly, EAP and other technologies that hit my road.

Tuesday, July 21, 2009

Generating Static WAR Content Archive with Maven

08:48 Tuesday, July 21, 2009 Posted by Markus Eisele
, , , , ,
You may have seen my simple JEE5 maven project setup already. I am trying to add more and more features during the next few weeks that satisfy the needs of enterprise software development.

First add-on is the possibility to have a separate static-web.zip generated, which contains all relevant content, that should be deployed to a separate webserver.

All you have to do is to add the following to your war/pom.xml

<plugin>
<!-- assamble static content -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/static.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Next step is to add a new folder in the web project (src\main\assembly) and create the needed assembly file (static.xml)

<assembly>
<id>static</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.html</include>
<include>**/*.htm</include>
<include>**/*.jpg</include>
<include>**/*.gif</include>
<include>**/*.css</include>
<include>**/*.js</include>
</includes>
<excludes>
<exclude>WEB-INF/*</exclude>
</excludes>
<outputDirectory>/static</outputDirectory>
</fileSet>
</fileSets>
</assembly>


If you now run maven clean install than you get a new static-web.zip file generated, which contains all the defined files and folders.