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

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">

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
<sharedlib.vendor>Igor Kromin</sharedlib.vendor>

Now with those properties set I I can define the configuration for maven-war-plugin. It looks a little like this...
 Maven POM

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

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


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.