将共享库附加到 WebSphere 应用程序的模块
Attaching shared-libs to WebSphere application's module
根据 IBM 文档,我编写了一个 jython 脚本,用于将共享库添加到现有应用程序。
# 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()
不幸的是,这只是为应用程序而非模块设置共享库。我怎样才能为两者设置库?
我试图获取应用程序的模块,但无法获取它的类加载器。
顺便说一句,sharedClassloader
属性用于什么?
注意:我知道这是不好的做法,但我继承了一堆遗留应用程序,所以请不要建议删除共享库或添加 deployment.xml
嗯,这是工作脚本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()
我认为实现此目的的一个好方法是在服务器级别创建一个共享库,然后也在服务器级别创建一个类加载器以加载库。
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()
感谢 poussma 提供的 jython 脚本,它适用于以前版本的 WAS...
所以我调整了你的代码,让它在 WAS8 上也能工作:
运行 命令行: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()
根据 IBM 文档,我编写了一个 jython 脚本,用于将共享库添加到现有应用程序。
# 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()
不幸的是,这只是为应用程序而非模块设置共享库。我怎样才能为两者设置库?
我试图获取应用程序的模块,但无法获取它的类加载器。
顺便说一句,sharedClassloader
属性用于什么?
注意:我知道这是不好的做法,但我继承了一堆遗留应用程序,所以请不要建议删除共享库或添加 deployment.xml
嗯,这是工作脚本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()
我认为实现此目的的一个好方法是在服务器级别创建一个共享库,然后也在服务器级别创建一个类加载器以加载库。
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()
感谢 poussma 提供的 jython 脚本,它适用于以前版本的 WAS... 所以我调整了你的代码,让它在 WAS8 上也能工作:
运行 命令行: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()