2

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

poussma
  • 7,033
  • 3
  • 43
  • 68
  • for people working on this. One option is during install: **MapSharedLibForMod** ; otherwise as here used check out **LibraryRef** – Tilo Feb 11 '16 at 23:36

3 Answers3

2

I think a good way to accomplish this is to create a shared library at the server level, and then create a classloader also on the server level in order to load the libraries.

set serv [$AdminConfig getid /Cell:mycell/Node:mynode/Server:server1/]

print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'],     ['classPath',  
'home/myProfile/mySharedLibraryClasspath']])

AdminConfig.create('Library', serv,     [['name', 'mySharedLibrary'],              
['classPath','test1.jar;test2.jar;test3.jar']]) 

appServer = AdminConfig.list('ApplicationServer', serv)
print appServer

classLoad = AdminConfig.showAttribute(appServer, 'classloaders')
cleanClassLoaders = classLoad[1:len(classLoad)-1]
classLoader1 = cleanClassLoaders.split(' ')[0]

classLoader1 = AdminConfig.create('Classloader', appServer,     [['mode',  'PARENT_FIRST']])

print AdminConfig.create('LibraryRef', classLoader1,     [['libraryName', 'MyshareLibrary']])

AdminConfig.save()

AdminNodeManagement.syncActiveNodes()
T_Man
  • 76
  • 7
1

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()
poussma
  • 7,033
  • 3
  • 43
  • 68
1

Thanks poussma for your jython script, it works on the previous version of WAS... so i adjusted your code to make it work also on WAS8 :

Run the cmd line with : addSharedLibrary.py <application-name> [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('\r')
    webModules = map(lambda s: s.strip(), webModules)
    for webModule in webModules:
        if (webModule.find(applicationName+'.ear') != -1):
            print 'Setting for ' + webModule
            addSharedLibrary(webModule)


dep = AdminConfig.getid('/Deployment:' + sys.argv[0] + '/')
addSharedLibrary(AdminConfig.showAttribute(dep, 'deployedObject'))
handleWebModules(sys.argv[0])

AdminConfig.save()