Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
I've written previously about how to use Ant to package a shared library for WebLogic, now that I've started using Maven more it is time to see how to do the same thing by creating a pom.xml file and running mvn package.

The first thing to do is to create a new pom.xml file for the shared library. A simple example can look like this...
 Maven POM
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>net.igorkromin</groupId>
<artifactId>MySharedLib1</artifactId>
<version>1.0.0</version>
<name>${project.artifactId}</name>
<packaging>war</packaging>
</project>


That of course is not enough but the important part to take away from the snippet above is the package is set to war. This means we will be using maven-war-plugin to create the package, this is configured a little bit later on.

Before continuing I like to set up a number of properties to make the pom.xml file more portable. In this case I define all the key elements I would like to configure for my shared library by adding a properties section to the pom.xml file...
 Maven POM
<properties>
<sharedlib.name>net.igorkromin.sharedlib1</sharedlib.name>
<sharedlib.vendor>Igor Kromin</sharedlib.vendor>
<sharedlib.spec.version>1.0</sharedlib.spec.version>
<sharedlib.impl.version>1.0.0</sharedlib.impl.version>
</properties>




Now with those properties set I I can define the configuration for maven-war-plugin. It looks a little like this...
 Maven POM
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<compress>true</compress>
<manifestEntries>
<Specification-Title>${sharedlib.name}</Specification-Title>
<Specification-Version>${sharedlib.spec.version}</Specification-Version>
<Implementation-Title>${sharedlib.name}</Implementation-Title>
<Implementation-Version>${sharedlib.impl.version}</Implementation-Version>
<Implementation-Vendor>${sharedlib.vendor}</Implementation-Vendor>
<Extension-Name>${sharedlib.name}</Extension-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>


The configuration is fairly straight forward, all it does is set failOnMissingWebXml to false so that the packager ignores the fact that we don't have a deployment descriptor (since it is not needed in this case). It sets up the manifest file in a way that WebLogic would recognise.


Ok so far so good but where are the JAR files that make up the shared library? This is configured through dependencies. Assuming you already have the JAR file either in your local Maven repository or in the remote repository, simply define a compile scope dependency and the JAR file will be included automatically. It is possible to have multiple JARs in the final WAR file simply by defining multiple dependencies like this.
 Maven POM
<dependencies>
<dependency>
<groupId>net.igorkromin</groupId>
<artifactId>SharedJar1</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>


Now just put all that together into one pom.xml file and you're good to go.

-i

Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...