Configuring a shared library for an application using wsadmin scripting
This task uses the AdminConfig object to configure a shared library for an application. Shared libraries are files used by multiple applications. Create a shared library to reduce the number of duplicate library files on your system.
Before you begin
There are two ways to complete this task. The example in this topic uses the AdminConfig object to create and configure a shared library. Alternatively, you can use the createSharedLibrary script in the AdminResources script library to configure shared libraries.
The scripting library provides a set of procedures to automate the most common administration functions. You can run each script procedure individually, or combine several procedures to quickly develop new scripts.
Procedure
- Start the wsadmin scripting tool.
- Identify the shared library and assign it to the library
variable. You can either use an existing shared library or create
a new one, for example:
- To create a new shared library, perform the following steps:
- Identify the node and assign it to a variable, for example:
- Using Jacl:
set n1 [$AdminConfig getid /Cell:mycell/Node:mynode/] - Using Jython:
n1 = AdminConfig.getid('/Cell:mycell/Node:mynode/') print n1
Example output:Table 1. getid command elements. Run the getid command to identify a shared library. Element Description setis a Jacl command n1is a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere® Application Server configuration getidis an AdminConfig command Cellis the object type mycellis the name of the object that will be modified Nodeis the object type mynodeis the name of the object that will be modified mynode(cells/mycell/nodes/mynode|node.xml#Node_1) - Create the shared library in the node. The following example creates
a new shared library in the node scope. You can modify it to use the
cell or server scope.
Using Jacl:
set library [$AdminConfig create Library $n1 {{name mySharedLibrary} {classPath c:/mySharedLibraryClasspath}}]Using Jython:
library = AdminConfig.create('Library', n1, [['name', 'mySharedLibrary'], ['classPath', 'c:/mySharedLibraryClasspath']]) print library
Example output:Table 2. create Library command elements. Run the create command to create a shared library. Element Description setis a Jacl command libraryis a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration createis an AdminConfig command Libraryis an AdminConfig object n1evaluates to the ID of host node specified in step number 1 nameis an attribute mySharedLibraryis the value of the name attribute classPathis an attribute /mySharedLibraryClasspathis the value of the classPath attribute MySharedLibrary(cells/mycell/nodes/mynode|libraries.xml#Library_1)
- Identify the node and assign it to a variable, for example:
- To use an existing shared library, issue the following command:
- Using Jacl:
set library [$AdminConfig getid /Library:mySharedLibrary/] - Using Jython:
library = AdminConfig.getid('/Library:mySharedLibrary/') print library
Example output:Table 3. getid Library command elements. Run the getid command to identify a shared library. Element Description setis a Jacl command libraryis a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration getidis an AdminConfig command Libraryis an attribute mySharedLibraryis the value of the Library attribute MySharedLibrary(cells/mycell/nodes/mynode|libraries.xml#Library_1)
- To create a new shared library, perform the following steps:
- Identify the deployment configuration object for the application
and assign it to the deployment variable. For example:
- Using Jacl:
set deployment [$AdminConfig getid /Deployment:myApp/] - Using Jython:
deployment = AdminConfig.getid('/Deployment:myApp/') print deployment
Example output:Table 4. getid Deployment command elements. Run the getid command to identify a deployment object. Element Description setis a Jacl command deploymentis a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration getidis an AdminConfig command Deploymentis an attribute myAppis the value of the Deployment attribute printis a Jython command myApp(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#Deployment_1) - Retrieve the application deployment and assign it to the appDeploy variable.
For example:
- Using Jacl:
set appDeploy [$AdminConfig showAttribute $deployment deployedObject] - Using Jython:
appDeploy = AdminConfig.showAttribute(deployment, 'deployedObject') print appDeploy
Table 5. showAttribute deployment command elements. Run the showAttribute command to assign a deployed object. Element Description setis a Jacl command appDeployis a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration showAttributeis an AdminConfig command deploymentevaluates the ID of the deployment configuration object specified in step number 2 deployedObjectis an attribute of modify objects printis a Jython command Example output:(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationDeployment_1) - Identify the class loader in the application deployment
and assign it to the classLoader variable. For
example:
- Using Jacl:
set classLoad1 [$AdminConfig showAttribute $appDeploy classloader] - Using Jython:
classLoad1 = AdminConfig.showAttribute(appDeploy, 'classloader') print classLoad1
Table 6. showAttribute appDeploy command elements. Run the showAttribute command to assign a class loader. Element Description setis a Jacl command classLoad1is a variable name $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration showAttributeis an AdminConfig command appDeployevaluates the ID of the application deployment specified in step number 3 classLoaderis an attribute of modify objects printis a Jython command Example output:(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#Classloader_1) - Associate the shared library in the application through
the class loader. For example:
- Using Jacl:
$AdminConfig create LibraryRef $classLoad1 {{libraryName MyshareLibrary}} - Using Jython:
print AdminConfig.create('LibraryRef', classLoad1, [['libraryName', 'MyshareLibrary']])
Table 7. create LibraryRef command elements. Run the create command to create a library reference. Element Description $is a Jacl operator for substituting a variable name with its value AdminConfigis an object representing the WebSphere Application Server configuration createis an AdminConfig command LibraryRefis an AdminConfig object classLoad1evaluates to the ID of class loader specified in step number 4 libraryNameis an attribute MyshareLibraryis the value of the libraryName attribute Example output:(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#LibraryRef_1) - Save the configuration changes. Use the following command example to save your configuration changes:
AdminConfig.save()