Tuesday, March 6, 2012

Use WebSphere wsadmin Jython to customise Web module context root for WAR/EAR deployment

This note explain how to use wsadmin Jython to customise Web module context root for WAR/EAR deployment in WebSphere Application Server.

To deploy WAR/EAR file in WAS WebSphere Application Server, wsadmin Jython provides the AdminApp.install method, where the archivePath parameter gives the full path of the war/ear file, and the options parameter gives various options for deployment, including the context root setting.

AdminApp.install(archivePath, options)

For WAR deployment, the -contextroot option is used, the option value is the given context root.

options = []
...
options.append("-contextroot")
options.append(contextRoot)
...
AdminApp.install(warPath, options)

For EAR deployment, the -CtxRootForWebMod option is used, the option value is a list consists of three items: Web module name, Web module URI, and the given context root. The Web module name and URI values can be set in two ways, using specific values, or using pattern matching:

#Set Web module name and URI with specific values
options = []
...
options.append("-CtxRootForWebMod")
options.append([['My Web Applicaiton', 'my_app.war,WEB-INF/web.xml', contextRoot]])
...
AdminApp.install(earPath, options)

#Set Web module name and URI using pattern matching
options = []
...
options.append("-CtxRootForWebMod")
options.append([['.*', '.*', contextRoot]])
...
AdminApp.install(earPath, options)

1 comment: