websphereshared-librariesjythonwsadmin

Attaching shared-libs to WebSphere application's module


Based on IBM documentation, I wrote a jython script that adds shared libs to an existing application.

# Application name
app = sys.argv[0]

dep = AdminConfig.getid('/Deployment:' + app + '/')
depObject = AdminConfig.showAttribute(dep, 'deployedObject')
classldr = AdminConfig.showAttribute(depObject, 'classloader')

for x in range(1, len(sys.argv)):
    AdminConfig.create('LibraryRef', classldr, 
                       [['libraryName', sys.argv[x]], ['sharedClassloader', 'true']])

AdminConfig.save()

Unfortunately, this is setting the shared library only for the application and not for the modules. How could I achieve setting the libraries for both ?

I tried to get the modules of an application but I cannot get the classloader of it.

enter image description here

BTW, what is the sharedClassloader attributes used for ?

Note: I know this is bad practice, but I inherited a bunch of legacy applications, so please don't advice to get rid of shared libs or to add a deployment.xml


Solution

  • Well, here is the working script addSharedLibrary.py <application-name> shared-lib [shared-lib...]

    def addSharedLibrary(holder):
        classldr = AdminConfig.showAttribute(holder, 'classloader')
        for x in range(1, len(sys.argv)):
            AdminConfig.create('LibraryRef', classldr, [['libraryName', sys.argv[x]], ['sharedClassloader', 'true']])
    
    
    def handleWebModules(applicationName):
        webModules = AdminConfig.list('WebModuleDeployment').split('\n')
        for webModule in webModules:
            if (webModule.find(applicationName) != -1):
                print 'Setting for ' + webModule
                addSharedLibrary(webModule)
    
    
    dep = AdminConfig.getid('/Deployment:' + sys.argv[0] + '/')
    addSharedLibrary(AdminConfig.showAttribute(dep, 'deployedObject'))
    handleWebModules(app)
    
    AdminConfig.save()