Home > Solutions Log > Optional Packages in Weblogic 10.3

Optional Packages in Weblogic 10.3

Optional Packages provide a great way to share individual jar files among multiple applications. Reusable java classes and third party framework classes are good candidates for deploying as optional packages. In this post I will show how to install and use Optional Packages in Weblogic 10.3.

I. Create Jar file
The first step in the process is to bundle a reusable Java class as a Jar file. To keep things simple, I will create a simple String Utility class.

 	
	public class StringUtil
	{
		public static boolean isEmpty(String text)
		{
			return null == text || "".equals(text);
		}
		
	}

The next step is to create a MANIFEST.MF file with the following information:

Manifest-Version: 1.0
Extension-Name: StringLib
Specification-Version: 1.0.0.0
Implementation-Version: 1.0.0.0

As you can see, the MANIFEST.MF file holds the information about the library such as name and version. The next step is to package the application into a jar file.

 

II. Install Optional Packages
Launch WebLogic console and click on Deployments:

Domain Structure

Domain Structure

Click on Install and on the next screen, browse to the folder containing the jar and select the jar:

Select Jar

Select Jar

Select the defaults on the next page and hit Finish. Restart the server for the changes to take effect.

 

III. Using Optional Packages in Web Application
Open the application’s MANIFEST.MF under META-INF folder and add the following entries:

Manifest-Version: 1.0
Extension-List: strlib
strlib-Extension-Name: StringLib
strlib-Specification-Version: 1.0.0.0
strlib-Implementation-Version: 1.0.0.0

Modify application’s code to start using the StringLib library. Even though Optional Packages are not deployed along with the application, you still might need them in your application’s class path during development. Maven users can do this by changing the jar dependency to provided in their pom.xml file.

 

Download stringlib.jar and demo war file along with source code here.

Categories: Solutions Log Tags:
  1. Matthias
    March 25th, 2010 at 01:55 | #1

    Thanks for this concise write-up, exactly the problem I was looking at a few days ago as well.

    On note on versioning (BEA WebLogic 10.3.2):

    it is not so obvious from WebLogic documentation that one needs to “Install” a second version of the Optional Package (say, with Implementation-Version: 1.0.1.0). Then you “update” the web application and it will pick up the later version of the OP-JAR.

    “Updating” the Optional Package JAR does not work since WL complains about missing internl structure (only EAR, WAR, EJB-JAR allowed).

    For “Java EE Shared Libraries”, it is “Install” that does not work (“name taken” message). Here, you need to go for “Update” which will also ask you whether you want to re-deploy the depending modules.

    But beware – NoClassDefFoundErrors are likely to appear (say, EAR with MDB accessing optional package classes). Still fighting class loader hell here, but liberal use of MANIFEST.MF/Class-Path: lines seem to help a bit.

    Regards,
    Matthias

  2. March 25th, 2010 at 08:35 | #2

    Thanks for sharing Matthias!!

  3. Richard Schuller
    May 4th, 2011 at 16:02 | #3

    @Matthias
    I am getting NoClassDefFoundErrors when trying to reference the optional package from an EJB inside an EAR. You mentioned Class-Path helped. Can you elaborate a bit?

    Great posting Balaji!!!

  1. No trackbacks yet.