How to configure EAR to access exisiting Websphere Shared Lib?

13,007

Solution 1

I found a way by simply following what WAS Admin Console was actually doing.

Create a deployment.xml in your EAR file if you do not have one already . You will find a reference to class loader like below

<classloader xmi:id="Classloader_1311552732281" mode="PARENT_FIRST">

Modify it and add reference to the shared Liberary created on server like below

 <classloader xmi:id="Classloader_1311552732281" mode="PARENT_FIRST">
        <libraries libraryName="JSF2_SHARED_LIB" sharedClassloader="true"/>
 </classloader>

@dbreaux has also shown a way .Accpeting my own answer as fits my needs better but big thanks to dbreaux too for advice.

Solution 2

Is the issue just that you don't want to have to configure each application separately, or that you don't want to use the admin console at all? You can associate a shared library with an entire server, which might be preferable to doing it for each app.

The other way to create those application associations is in the WebSphere-specific .xmi deployment files. These are created when you deploy but can also be included in WAR/EAR files. I don't know if that would help you at all. If it would, the official way to create them ahead of time is using one of the Deployment Tools, but since they're just XML, you may feel comfortable creating them manually.

Solution 3

To append extra details to Shahzeb's answer: My environment: Websphere 8.5; Windows 7;(Eclipse Luna to generate testing .war file)

I have installed the war file exported from eclipse on websphere server by websphere console. Then exported it again and unpack it to see what websphere automatically add to it to generate EAR.

[folder]META-INF
  [folder]ibmconfig
  [file]application.xml
  [file]ibm-application-bnd.xmi
  [file]ibm-application-runtime.props
  [file]MANIFEST.MF
  [file]was.module
  [file]was.policy
  [file]was.webmodule

[file]myWAR.war

And the file deployment.xml is placed in ..\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

whose content in form of


<?xml version="1.0" encoding="UTF-8"?>
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1417052686904">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1417052686904" deploymentId="0" startingWeight="1" binariesURL="$(APP_INSTALL_ROOT)/[server service name]Cell/myWAR.ear" useMetadataFromBinaries="false" enableDistribution="true" createMBeansForResources="true" reloadEnabled="false" appContextIDForSecurity="href:[server service name]Cell/myWAR" filePermission=".*\.dll=755#.*\.so=755#.*\.a=755#.*\.sl=755" allowDispatchRemoteInclude="false" allowServiceRemoteInclude="false" asyncRequestDispatchType="DISABLED" standaloneModule="true" enableClientModule="false">
    <targetMappings xmi:id="DeploymentTargetMapping_1417052686904" enable="true" target="ServerTarget_1417052686904"/>
    <classloader xmi:id="Classloader_1417052686904" mode="PARENT_FIRST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1417052686904" deploymentId="1" startingWeight="10000" uri="myWAR.war" containsEJBContent="0">
      <targetMappings xmi:id="DeploymentTargetMapping_1417052686905" target="ServerTarget_1417052686904"/>
      <classloader xmi:id="Classloader_1417052686905"/>
    </modules>
    <properties xmi:id="Property_1417052686904" name="metadata.complete" value="true"/>
  </deployedObject>
  <deploymentTargets xmi:type="appdeployment:ServerTarget" xmi:id="ServerTarget_1417052686904" name="server1" nodeName="[server service name]"/>
</appdeployment:Deployment>

(Since I have no reputation, I have to do it all in text.. )

Share:
13,007
Shahzeb
Author by

Shahzeb

Software Rules Software is a tool, not salvation. Management will buy software as a salvation. No software is TURNKEY. Management believes all software is TURNKEY. The software you use always looks buggy. It is always easier to blame the software for work problems than pointing out real problems to management. The software the salesman is showing you always looks bugless. When no one reports a bug or complains about software, one of the following is true: - No one is using it - A natural disaster has disabled all forms of communication.

Updated on June 05, 2022

Comments

  • Shahzeb
    Shahzeb about 2 years

    I am using JSF2 with Websphere 7 . I have created a shared lib successfully and have pointed application using Webpsphere Admin Console and it works successfully . But what we really want to do is to not have to point to that Shared Lib via WAS Admin Console but have some sort of application level configuration e.g in deployment.xml etc which we can point to the name of that Shared Isolated Lib and use it . I have gone through SO and google but not found any thing doing that . I however know that there are commercial application doing it but do not know how .
    This question from How can I specify a shared library reference at the web module level in Websphere 6.1 deployment descriptors? is closely what I am after but I not want to specify version numbers or jar names as the answer states

  • Shahzeb
    Shahzeb almost 13 years
    Issue was that we did not want to associate with entire server as there were some applications using JSF1.2 and Administrators did not want to associate with via server console (not sure why :) ) I managed to do what admin console does behind the scene by creating an entry in standard deployment.xml.Thanks for your answer I have voted it up.
  • Frans
    Frans about 7 years
    Associating shared library with entire server is a good suggestion.