Thursday, March 5, 2009

Changing Classloader Mode of modules inside an EAR in WebSphere Portal

Configuring WebSphere to change the classloader mode is done using WSADMIN. This is a commandline client which interprets scripts written in JACL or Jython. Most sources online can be found using JACL, so we will use JACL for changing the classloader mode.

The scriplet below can be copied and placed in a set_classloader_mode.jacl file:

### update classloader mode
proc classloaderMode {xappname xmode} {
###
### set up globals
###
global AdminConfig

set deployment [$AdminConfig getid /Deployment:$xappname/]
if {$deployment == {}} {
puts "app not found: $xappname"
} else {
set deployedObject [$AdminConfig showAttribute $deployment deployedObject]
set classloader [$AdminConfig showAttribute $deployedObject classloader]
set modules [lindex [$AdminConfig showAttribute $deployedObject modules] 0]
### below is EAR mode
### $AdminConfig modify $classloader [list [list mode $xmode]]

### below we update mode for all web/ejb modules in the ear
foreach module $modules {
$AdminConfig modify $module [list [list classloaderMode $xmode]]
}

###
### Save all the changes
###
puts " "
puts "Saving the configuration"
$AdminConfig save
}
}

###
### Main
###

if { ($argc < 1) } {
puts " "
puts "set_classloader_mode.jacl "
puts " "
puts "Usage: wsadmin.sh -username system -password password -f set_classloader_mode.jacl appName \[PARENT_FIRST|PARENT_LAST\]"
puts " "
puts "For example: "
puts " "
puts "wsadmin.sh -username system -password password -f set_classloader_mode.jacl gcm PARENT_LAST"
puts " "
} else {
set appName [lindex $argv 0]
if { ($argc == 2) } {
set mode [lindex $argv 1]
} else {
set mode "PARENT_LAST"
}
classloaderMode $appName $mode
}

The set_classloader_mode.jacl can be executed using WSADMIN as follows:

$ /bin/wsadmin.sh -user -password -f set_classloader_mode.jacl [PARENT_LAST|PARENT_FIRST]

The appName is the name of your EAR without the .ear. So if EAR=test.ear then appName=test. The second parameter behind the JACL script is optional. Default PARENT_LAST is used.