blob: 1adfefd4238d0c6f8db75aa3ead96ba7acc32a47 [file] [log] [blame]
------
Creating Skinny WARs
------
Mike Perham
Dennis Lundberg
------
2011-12-09
------
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
Creating Skinny WARs
In a typical J2EE environment, a WAR is packaged within an EAR for deployment. The
WAR can contain all its dependent JARs in <<<WEB-INF/lib>>> but then the EAR can quickly grow
very large if there are multiple WARs, due to the presence of duplicate JARs. Instead
the J2EE specification allows WARs to reference external JARs packaged within the EAR
via the <<<Class-Path>>> setting in their <<<MANIFEST.MF>>>.
Starting with version 2.7 Maven EAR Plugin has basic support for this mode of
operation.
First we need to change the EAR project's <<<pom.xml>>> to package those JARs
in the EAR, using the <<<skinnyWars>>> parameter.
<<Note:>> In this example we package all JARs into a <<<lib/>>> directory
within the EAR. This is just to distinguish between J2EE modules (which will be
packaged in the root of the EAR) and Java libraries (which are packaged in
<<<lib/>>>).
+-----------------+
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
+-----------------+
Now the painful part. Your EAR project's <<<pom.xml>>> needs to list every
dependency that you want to share through the EAR.
+-----------------+
<project>
....
<dependencies>
<!-- This is the JAR we want to share -->
<dependency>
<groupId>com.acme</groupId>
<artifactId>shared-jar</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.acme</groupId>
<artifactId>war1</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.acme</groupId>
<artifactId>war2</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
</dependencies>
...
</project>
+-----------------+
Your EAR will contain something like this:
+-----------------+
.
|-- META-INF
| `-- application.xml
|-- lib
| `-- shared-jar-1.0.0.jar
|-- war1-1.0.0.war
`-- war2-1.0.0.war
+-----------------+
If you look inside the copies of <<<war1-1.0.0.war>>> and <<<war2-1.0.0.war>>>,
that are packaged within the EAR, you will see that they no longer contain the
file <<<WEB-INF/lib/shared-jar-1.0.0.jar>>>.
Also, if you inspect the <<<MANIFEST.MF>>> of the WARs you will notice that the
<<<Class-Path>>> entry has been modified and now has a reference to
<<<lib/shared-jar-1.0.0.jar>>>.