Question

I have a JEE application that runs on WAS 6. It needs to have the class loader order setting to "Classes loaded with application class loader first", and the WAR class loader policy option set to "Single class loader for application".

Is it possible to specify these options inside the EAR file, whether in the ibm-web-bnd.xmi file or some other file, so the admin doesn't need to change these setting manually?

Since the app is deployed via an automated script, and the guy who is in charge of deployment is off site, and also for some other political reasons, this would greatly help!

Was it helpful?

Solution

Thanks to @Matthew Murdoch's answer, I was able to come up with a solution. Here it is, in case it helps someone else.

I created a deployment.xml like this:

<?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_1241112964096">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1241112964096" startingWeight="1" warClassLoaderPolicy="SINGLE">
    <classloader xmi:id="Classloader_1241112964096" mode="PARENT_LAST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1241112964096" startingWeight="10000" uri="AGS.war">
      <classloader xmi:id="Classloader_1241112964097"/>
    </modules>
  </deployedObject>
</appdeployment:Deployment>

Make sure to change the name of your WAR file(s) to match (mine is called AGS.war).

I also changed the numbers in the xmi:id attributes, to be sure they are unique, though I'm not sure it it really matters that they be unique across applications.

Then, I put the deployment.xml file in the root of my EAR file, via ANT:

    <ear destfile="${artifactsDir}/${earName}.ear" appxml="${projectName}_EAR/application.xml">
        <fileset dir="${artifactsDir}" includes="${warName}.war"/>
        <fileset dir="${projectName}_EAR/" includes="deployment.xml"/>
    </ear>

OTHER TIPS

Edit (2): The WebSphere Application Server Toolkit (AST) is a tool you can use to enhance an EAR file with this information (see for example the 'Configure an Enhanced EAR' section in this document).

Edit (1): This post suggests that the 'Classes loaded with application class loader first' (the PARENT_LAST setting) can be set in the deployment.xml file within the EAR.

If you have control over the automated deployment scripts this can be done. Below is some wsadmin jython code for setting the web module class loader order to 'Classes loaded with application class loader first' (interestingly the setting is called PARENT_LAST which is what it was labelled in previous versions of the admin console...).

wsadmin example (jython):

def getWebModule(config, applicationName):
    webModules = config.list('WebModuleDeployment').
         split(system.getProperty('line.separator'))
    for webModule in webModules:
        if (webModule.find(applicationName) != -1):
            return webModule
    return None

applicationName = "<Your application name here>"

webModule = getWebModule(AdminConfig, applicationName)
if (webModule != None):
    AdminConfig.modify(webModule, "[[classloaderMode PARENT_LAST]]")
    AdminConfig.save()
else:
    print "Error: Cannot find web module for application: " + applicationName

Check out this link. There are different ways to set class loader policy using Jython based on your server version - http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frxml_7libapp4.html

Similar to the answer from pkaeding, I discovered as follows, not specific to a particular .war by name, but useful when applying to whatever is the default .war in the .ear file. (.ear files with one .war file in them have only that .war, so naming the .war isn't necessary in the entry.) This approach may be good for situations where you may need to re-name of the .war project later for some reason, and so you wouldn't need to worry about updating the deployment.xml file. I found the deployment.xml file buried inside a cell reference directory trail; dunno if it's fine as shown when the file is placed at directory level META-INF and no deeper.

In my particular case, I found deployment.xml in my .ear project at:

<project_root>\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

The content of the file looks a lot like:

<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_1262775196208">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment"
    xmi:id="ApplicationDeployment_1262775196208" startingWeight="10">
      <classloader xmi:id="Classloader_1262775196208" mode="PARENT_LAST" />
  </deployedObject>
</appdeployment:Deployment>

The line:

<classloader xmi:id="Classloader_1262775196208" mode="PARENT_LAST" />

originally read:

<classloader xmi:id="Classloader_1262775196208" mode="PARENT_FIRST" />

Note no reference to any .war is being made. As pkaeding mentioned, you shouldn't expect the various id numbers to be the same for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top