Hi,

Jay SenSharma

Jay SenSharma

According to the following Link: http://download.oracle.com/docs/cd/E15523_01/web.1111/e13706/libraries.htm#i1064656

A shared Java EE library is a single module or collection of modules that is registered with the Java EE application container upon deployment. A shared Java EE library can be any of the following:
1) Standalone EJB module
2) Standalone Web application module
3) Multiple EJB modules packaged in an Enterprise Application
4) Multiple Web application modules package in an Enterprise Application
5) Single plain JAR file as well

A WebLogic Shared Library is an Enterprise Application Archive, a stand-alone EJB, a Web Application module, or a JAR file that is registered with the WebLogic Server as a shared library. The library resources can be shared between multiple applications, alleviating the need to have duplicate copies of the resources in each application. For an overview of WebLogic Shared Libraries, see J2EE Library: Overview in the WebLogic Server documentation

Step1). Create a Directory some where in your file system like : D:DELETEReplication_Plan_xml
Step2). Now Create the First Shared Library Which contains a Simple Java Program …. Which is going to be accessed by an EAR Application later
Write a Program “MyTestClass.java”

package test.pack;
public class MyTestClass
{
static {
System.out.println(“nnt MyTestClass class Loaded From FirstSharedLibrary.jar”);
}

public String sayHello(String name)
{
System.out.println(“nnt MyTestClass class From FirstSharedLibrary.jar sayHello() called….”); ;
return “MyTestClass class From FirstSharedLibrary.jar, Welcome Mr: “+name;
}

public String sayNewHello(String name)
{
System.out.println(“nnt MyTestClass class From FirstSharedLibrary.jar sayNewHello() called….”); ;
return “MyTestClass class From FirstSharedLibrary.jar, Welcome Mr: “+name;
}
}

———————————
Step4). Now Compile the above class and Create a Jar of it like “FirstSharedLibrary.jar”
javac -d . MyTestClass.java
jar cvf FirstSharedLibrary.jar test

Step5). Now we will create another Shared Library named as “ThirdSharedLibrary.jar”So we will write another class “ThirdLibraryClass.java”

package third.pack;
public class ThirdLibraryClass
{
static {
System.out.println(“nnt ThirdLibraryClass class Loaded From ThirdSharedLibrary.jar”);
}

public String sayHello(String name)
{
System.out.println(“nnt ThirdLibraryClass class From ThirdSharedLibrary.jar sayHello() called….”); ;
return “ThirdLibraryClass class From ThirdSharedLibrary.jar, Welcome (ThirdLibrary)Mr: “+name;
}
}
———————————
Step6). Now Compile the above class and Create a Jar of it like “ThirdSharedLibrary.jar”
javac -d . ThirdLibraryClass.java
jar cvf ThirdSharedLibrary.jar third

Step7). Depoy the First Shared library in WebLogic Server (Example AdminServer):

Step8). Now Deploy the Second Shared Library as well.

Step 9). Now We will create an Enterprise Application to use these Shared Libraries….

In the EAR file we will have a WebApplication with two JSP Pages
“index.jsp”

<%@ page language=”java” contentType=”text/html;charset=UTF-8?%>
<html>
<body>
Hi this is Line1<BR>
<%
System.out.println(“nnt -1-“);
test.pack.MyTestClass mtc=new test.pack.MyTestClass();
System.out.println(“nnt -2-“+mtc.sayHello(“Jack”));;
%>
Hi this is Line2<BR>
<a href=ThirdLibraryTest.jsp>Click Here to Test Newly Added Library</a>
</body>
</html>
———————————

“ThirdLibraryTest.jsp”

<%@ page language=”java” contentType=”text/html;charset=UTF-8?%>
<html>
<body>
(ThirdLibraryTest)- Hi this is Line1<BR>
<%
System.out.println(“nnt -1-“);
third.pack.ThirdLibraryClass mtc=new third.pack.ThirdLibraryClass();
System.out.println(“nnt -2-“+mtc.sayHello(“Jack”));;
%>
(ThirdLibraryTest)- Hi this is Line2<BR>
</body>
</html>

Now Provide the “web.xml” file inside your WAR file (you can use any Dummy web.xml).

To create an EAR file we need to provide the “application.xml” like below:
“application.xml”

<?xml version=”1.0″ encoding=”UTF-8″?>
<application id=”Application_ID” version=”1.4? xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd”>
<display-name>TestSharedProjectEAR</display-name>
<module id=”WebModule_1253802759716″>
<web>
<web-uri>TestSharedProject</web-uri>
<context-root>TestSharedProject</context-root>
</web>
</module>
</application>
———————————
“weblogic-application.xml”

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<weblogic-application xmlns=”http://www.bea.com/ns/weblogic/90″>
<application-param>
<param-name>webapp.encoding.default</param-name>
<param-value>UTF-8</param-value>
</application-param>
<library-ref>
<library-name>FirstSharedLibrary</library-name>
</library-ref>
</weblogic-application>

Step 9). Now Deploy the EAR Application on WebLogic Server (Note This EAR file already has the Library reference for the “FirstSharedLibrary”)

Step 10). Now you can see the AdminConsole to check the Deployments:

Step 11). Now access the EAR application like following

http://10.10.71.139:7001/SonaliProject/

Step 12). Now if we will click on the Click Here to Test Newly Added Library link then we will get the following error message: (Because EAR is currently now referring the ThirsSharedLibrary)

Step 13). Now Update the EAR application using the “plan.xml” file provided as part of the TestCase:
“plan.xml”

<?xml version=’1.0′ encoding=’UTF-8′?>
<deployment-plan xmlns=”http://www.bea.com/ns/weblogic/90″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-deployment-plan.xsd”>
<application-name>SonaliProjectEAR</application-name>

<variable-definition>
<variable>
<name>MyThirdLibrary</name>
<value>ThirdSharedLibrary</value>
</variable>
</variable-definition>

<module-override>
<module-name>SonaliProjectEAR</module-name>
<module-type>ear</module-type>
<module-descriptor external=”false”>
<root-element>weblogic-application</root-element>
<uri>META-INF/weblogic-application.xml</uri>
<variable-assignment>
<name>MyThirdLibrary</name>
<xpath>/weblogic-application/library-ref/library-name</xpath>
<operation>add</operation>
</variable-assignment>
</module-descriptor>
</module-override>
<config-root xsi:nil=”true”></config-root>
</deployment-plan>

And then finish the Update.

Now again try to access the Application ….. This time we will be able to access the Second Library too through EAR application.

As well as now we can even see in the Admin Console that the Third Shared Library is also accessible by the EAR application: