Hi,
Optional packages feature of WebLogic allows us to easily share a single JAR file among multiple applications.
When to Use it?
Secnario: Third-party Web Application Framework classes needed by multiple Web applications can be packaged and deployed in a single JAR file, and referenced by multiple Web application modules in the domain.
1. Optional packages are delivered as basic JAR files that have no deployment descriptors. You simply designate the JAR as an optional package at deployment time, and WebLogic Server registers the file with the target servers you select. After the optional package has been registered, you can then deploy J2EE modules and applications that reference the optional package in their MANIFEST.MF files.
2. Optional packages feature of WebLogic allows us to easily share a single JAR file among multiple applications. When to Use it? Third-party Web Application Framework classes needed by multiple Web applications can be packaged and deployed in a single JAR file, and referenced by multiple Web application modules in the domain.
3. Optional packages are delivered as basic JAR files that have no deployment descriptors. You simply designate the JAR as an optional package at deployment time, and WebLogic Server registers the file with the target servers you select. After the optional package has been registered, you can then deploy J2EE modules and applications that reference the optional package in their MANIFEST.MF files.
For more Informations please refer to : http://download.oracle.com/docs/cd/E15051_01/wls/docs103/deployment/understanding.html#wp1052671
A real time demo and TestCase here : http://forums.oracle.com/forums/thread.jspa?threadID=2173886&tstart=0
Here i am going to demonstrate a Very Simple Step procedure to utilize Optional Packages in our applications.
Developing Shared Library
Step 1). Just write a Simple Java Program … Lets say “HelloWorld.java”
package hello.pack; public class HelloWorld { public void HelloWorld() { System.out.println("Hello World!"); } public String sayHello(String name) { System.out.println("nt sayHello(String) method of class HelloWorld Invoked... "); return "Hello Mr. "+name; } }
Step2 ). Compile the Program as usual
D:/DELETE/OptionalPackageDemo>javac -d . HelloWorld.java
Step 3). Now We need to provide the “META-INF/MANIFEST.MF” file before creating the JAR. So first of all In the Current Directory create a Folder with name “META-INF” and inside it create a File Named as “MANIFEST.MF” and then write the Extension-Name inside the file. Like Folliwing…
Manifest-Version: 1.0 Class-Path: Extension-Name: HelloWorld
D:/DELETE/OptionalPackageDemo> jar -cvfM HelloWorld.jar hello META-INF MANIFEST.MF
NOTE: Make sure that in above command you use the JAR flags as:
(c=create, v=verbose, f=file, Capital M=add our own MANIFEST.MF file and dont create a default one)
Step 5). Now Deploy this JAR file in WebLogic Server …It’s Very Simple Just Login to AdminConsole of WebLogic Server and then Click on Lock and Edit then Just deploy it as a library …Thats all.
Using the Optional Package “HelloWorld.jar” in our Application?
Just follow the below mentioned Steps:
Step 6). Develop one Web Application …with “index.jsp” page as mentioned below:
<%@ page import=”com.test.hello.*” %> <% hello h = new hello(); h.HelloWorld(); out.println(“<h2> h.sayHelloWorld(Jack) : ” +h.sayHelloWorld(“Jack”)); %>
Step 7). Provide the default “WEB-INF/web.xml” file…like
<!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN” “http://java.sun.com/dtd/web-app_2_3.dtd”> <web-app> </web-app>
Step 8). Just Beside the “WEB-INF” Folder Create another Folder “META-INF” and then inside the META-INF folder create a file “MANIFEST.MF” with following entries…
Manifest-Version: 1.0 Class-Path: Extension-List: hello hello-Extension-Name: HelloWorld
Step 9). Now Create a WAR file which should include “index.jsp” file , “META-INF” and “WEB-INF” folders
D:/DELETE/TestWebApp> jar -cvfM TestWebApp.war META-INF WEB-INF index.jsp
NOTE: jar command has an Additional Flag this time
c = Create v = Verbose f = File M = (UPPER CASE M) Means Dont add a Default MANIFEST.MF in the WAR file…Rather Add Our Own “MANIFEST.MF” file in the Archieve.
Step 10). Now Just deploy this Above WAR file in WebLogic Server and then See that You are able to access the Index.jsp Page, which is reffering to a Class file “hello.pack.HelloWorld” which is not at all available inside the WAR …But we are able to access it in our WebApplication…Because of WebLogic’s Optional Package Feature
.
.
December 4th, 2010 on 10:12 pm
Hi Jay,
How this different from including the jar in the class path of the server ?. In that case also it will be outside the war.
Thanks
sumit
December 5th, 2010 on 9:03 pm
Hi Sumit,
When we Add a JAR in the CLASSPATH variable of the Server then The Class which is present inside the JAR will be Loaded and used for all the applications deployed on that Server. But with Optional Packages or Shared Library concept we can avoid unwanted Class Loading.
Example: Suppose In my Server 5 Applications are Deployed App_A, App_B, App_C, App_D and App_E, Now consider a scenario where Some Jar “ThirdParty_2.0.jar” class is required for APP_A, APP_B and APP_C but A latest version of that Jar is required for APP_D and APP_E. So in that case Optional Package Deployment is a best option.
The Application need to refer to the Optional Packages which they want to load. This flexibility is not available with the CLASSPATH setting at server level.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
February 2nd, 2011 on 10:16 pm
Here i am practicing on Optional Packages which is posted by the jay sensharma.
getting some error while trying to deploy the HelloWorld.jar file by using weblogic.Deployer tool.
Error is:
java weblogic.Deployer -adminurl t3://192.168.1.2:7001 -user weblogic -password passowrd -deploy -targets Admin -library /JavaPreparation/Optional_weblogic/HelloWorld.jar
weblogic.Deployer invoked with options: -adminurl t3://192.168.1.2:7001 -user weblogic -deploy -targets Admin -library /JavaPreparation/Optional_weblogic/HelloWorld.jar
Task 10 initiated: [Deployer:149117]deploy library HelloWorld.jar on Admin.
Task 10 failed: [Deployer:149117]deploy library HelloWorld.jar on Admin.
Target state: deploy failed on Server Admin
weblogic.application.library.LibraryDeploymentException: [J2EE:160141]Could not initialize the library /JavaPreparation/Optional_weblogic/HelloWorld.jar. Please ensure the deployment unit is a valid library type (war, ejb, ear, plain jar). invalid header field
I made the jar file as you said in the Weblogic Optional Packages Post…
February 2nd, 2011 on 11:43 pm
Hi Hemanth,
I have uploaded a Simple TestCase of 4KB size in the following link : http://www.4shared.com/file/TkB0G1Wq/OptionalPackageTestCase.html
Please try the above TestCase and let us know if it works for you. It has “HelloWorld.jar” (OptionalPackage) and a Simple WebApplication “TestWebApp” which refers to the HelloWorld Optional Package.
Please read carefully the “META-INF/MANIFEST.MF” inside the TestWebApp as well as inside the “HelloWorld.jar” ..there is the actual trick 😉
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
March 10th, 2011 on 1:26 am
Hi Jay,
I copied and tried your test sample. When I tried to deploy HelloWorld.jar, I got the same exception as the previous user hemanthgoud. Here is my jar file structure,
[oracle@entowl1q-vm test]$ jar -xvf HelloWorld.jar
created: hello/
created: hello/pack/
inflated: hello/pack/HelloWorld.class
created: META-INF/
inflated: META-INF/MANIFEST.MF
inflated: META-INF/HelloWorld.jar
Here is the content of MANIFEST.MF
Manifest-Version: 1.0
Class-Path:
Extension-Name: HelloWorld
As you stated in your email, what is the actual trick to make this work?
Thanks a lot,
-John
March 10th, 2011 on 1:58 am
Hi John,
I uploaded my TestCase in the following location :
http://www.4shared.com/get/XtcyrpOS/OptionalPackageDemo_2.html
Zip Name is “OptionalPackageDemo_2.zip”
I just now tested it in WLS10.3.0 and the Optional Package worked fine for me. I have mentioned the step by step instructions in the README.txt file in the above link Please click on the “Download Now” button in the above link to download the TestCase and let us know if you used the proper command to make the “HelloWorld.jar” with “-M” flag ?
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 7th, 2011 on 5:19 am
Hi Jay.
i’m writing from Peru.
What is the difference in using a shared library
July 7th, 2011 on 10:05 am
Hi Migueleiva,
Suppose if we have 3 Applications APP_A.ear, APP_B.ear and APP_C.ear and if all the 3 Applications are using JSF components so in that case we will have 2 alternatives to package our applications.
1). All the 3 Applications will individually contain all the JSF related JAR files inside their “APP-INF/lib” or “WEB-INF/lib” directory. (But this approach will be bad because in this case the Size of all the 3 Applications will be large because they are containing common JAR files)
2). So to over come the disadvantage of the above technique we use the concept of Shared Libraries. Now we deploy all the JARs which can be used by many applications commonly inside a single Shared Library and then other applications just refers to the shared library. So like this we can reduce the actual physical Size of an Application Archive, which gives us better performance at the time of deployment because the applications becomes light weight.
Optional packages also do the same thing as Shared Libraries but the only difference is the Optional Package is in form JAR files where as the Shared Libraries are in form of WAR or EAR. So if you want to share some single JAR file among different application then Optional Package is good approach but if you have a Set of many Jars which need to be shared by different applications then in that case we should chose Shared Library Deployment.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
September 16th, 2011 on 1:30 am
Jay,
I am planning to use shared libraries in weblogic for a web services project that talk to legacy applications.
Say application APP_A depends on the shared library test1.jar version 2.0
APP_A depends on the shared library sample.jar which in turn has dependency on test1.jar version 1.0
Is that possible to define shared library with two versions where parent(APP_A) depends on the latest version (2.0) and the child (sample.jar) and depends on the old version(1.0)
Please let me know as I hit a roadblock researching on this interdependency between 2 different versions.
Thanks
Vishy
October 27th, 2011 on 8:20 am
hello admins!!
maybe this is not the place where should i post my question but i dont know where should i…
my question is:
if i have an .ear package with a .jar for ejb and a .war module should i create a ejb-jar-client for the ejb module and place that client in the WEB-INF/lib of the .war module and edit the weblogic.xml with the prefer-web-inf-classes set to true so i can be able to use classes that i create for the ejb module?
my question is because in my ejbs i return in example a list List getUsers(); and in my webapp i need the User entity that is created in my ejb module.
i think if i compile all classes from ejb module to APP-INF/classes my webapp could be able to use it… right?
sorry if im not clear :_
thanx in advance for ur answer!
October 27th, 2011 on 1:50 pm
You can package it all as an ear, an example of such a structure is given here: http://middlewaremagic.com/weblogic/?p=6725. In particular look in the ‘Packing applications’ section.
November 7th, 2011 on 8:01 pm
thanx for reply René … i have problems because when i want to build the ear package i receive an exception in my jsp files the import of my entities fail.
December 13th, 2012 on 12:36 pm
Hi am New to weblogic i have 3 doubts please help me
1. In a domain only Admin server is runing reaming All managed servers are down how will you troubleshoot this issue.
2.How will you troubleshoot if Application is down?
3.what are the improtant parameters in nodemanager?
January 4th, 2013 on 4:31 pm
Hi Jay,
I have a question:
I have a jar which have bunch of class files and the package path be com.somecompany.someproduct and have bunch of class files like class1, class2 .. classn inside someproduct folder.
So in my ear file I am importing like
import com.somecompany.someproduct.class1
import com.somecompany.someproduct.class2
import com.somecompany.someproduct.class3 ..
Now in my ear manifest.mf file
I dont want to mention Extension-List: class1 class2 ..
How can I just mention to get all class like
Extension-List: com.somecompany.someproduct
I tried this, but getting ClassNotFound
Another question, is it mandatory for optional libraries to mention Extension-Name is MANIFEST ?
June 2nd, 2013 on 8:05 pm
Hi Team,
I am new to weblogic and i want to create a test environment using weblogic 12c.
My Query is to install weblogic ,whether i need a dedicated user or not?what are the steps i have to folow before installation.I am getting the folowing error while iam installing weblogic please help me.
java.util.prefs.FileSystemPreferences$2 run
May: not found
$ WARNING: Couldn’t create user preferences directory. User preferences are unusable.
> May 30, 2013 12:50:21 PM java.util.prefs.FileSystemPreferences$2 run
> WARNING: java.io.IOException: No such file or directory
java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
> WARNING: Could not lock User prefs. Unix error code 2.
> May 30, 2013 12:50:52 PM java.util.prefs.FileSystemPreferences syncWorld
> WARNING: Couldn’t flush user prefs: java.util.prefs.BackingStoreException: Couldn’t get file lock.
> ***]
Thanks and Regards,
Tarun:)