Shared Library example for Oracle Weblogic Server

1. Compile your code and package it in a jar file. In this example I have written a simple program that has a function that just takes a string as input and prints hello infront of the string.

 

package wonders;


public class MyTestClass
{

static {
System.out.println("MyTestClass class Loaded From sf1.jar");
}

public String sayHello(String name)
{
System.out.println("sf1.jar sayHello() called"); ;
return name;
}


}

2. Deploy the jar file on the server as a library.

3. Refer the shared library in the weblogic-application.xml present under EAR\META-INF folder.

 

<?xml version="1.0" encoding="ISO-8859-1"?>


<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application” 
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance 
xsi:schemaLocation=”http://xmlns.oracle.com/weblogic/weblogic-application 
http://xmlns.oracle.com/weblogic/weblogic-application/1.0/weblogic-application.xsd">

   <application-param>
      <param-name>webapp.encoding.default</param-name>
      <param-value>UTF-8</param-value>
   </application-param>
   <library-ref> 
   <library-name>sf1</library-name> 
   </library-ref>

</weblogic-application>

4. Access the library from your application. In my example I am calling the function from a jsp.

 <html> 
 
 <body> Hi this is hello from sl1.jar<BR> 
 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="wonders.*" %>
 
 
 <% wonders.MyTestClass mtc=new wonders.MyTestClass(); 
 System.out.println("Hello to "+ mtc.sayHello("Wonders")); %> 
 

 </body> 
 
 </html>

shared library

 

shared library1

Leave a Reply