+

Search Tips   |   Advanced Search

Configure a shared library

Use scripting to configure a shared library for application servers. Shared libraries are files used by multiple applications. Create a shared library to reduce the number of duplicate library files on the system.

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, we 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. We can run each script procedure individually, or combine several procedures to quickly develop new scripts.

  1. Start the wsadmin scripting tool.

  2. Identify the server and assign it to the server variable. For example:

    • Jacl:

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

    • Jython:

      serv = AdminConfig.getid('/Cell:mycell/Node:mynode/Server:server1/')
      print serv

    Element Description
    set is a Jacl command
    serv is a variable name
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    getid is an AdminConfig command
    Cell is an attribute
    mycell is the value of the attribute
    Node is an attribute
    mynode is the value of the attribute
    Server is an attribute
    server1 is the value of the attribute

    Example output:

      server1(cells/mycell/nodes/mynode/servers/server1|server.xml#Server_1)

  3. Create the shared library in the server.

    Following are examples of how to create the shared library using either Jacl or Jython.

    • Jacl:

      (dist)

        $AdminConfig create Library $serv {{name mySharedLibrary} {classPath c:/mySharedLibraryClasspath}}

      (zos)

        $AdminConfig create Library $serv {{name mySharedLibrary} {classPath /mySharedLibraryClasspath}}

      (iseries)

        $AdminConfig create Library $serv {{name mySharedLibrary} {classPath /home/myProfile/mySharedLibraryClasspath}}

    • Jython:

      (dist)

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

      (zos)

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

      (iseries)

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

    Avoid trouble:

    • If we are using Jython, and the classpath does not contain any spaces, we can use a semicolon (;) or a space as a separator. For example:

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

      or

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

    • If we are using Jacl, and the classpath contains one or more spaces, add additional braces or quotation marks around the classpath. For example:

        $AdminConfig create Library $serv {{name mySharedLibrary} {classPath {c:/JDBC Driver/test.jar}}}

      or

        $AdminConfig create Library $serv {{name mySharedLibrary} {classPath "c:/JDBC Driver/test.jar"}}

    • If we are using Jython, and the classpath contains one or more spaces, use a semicolon (;) as a separator. For example:

        AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath','c:/JDBC Driver/test.jar;a.jar']])

      or if there is only one path:

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

    • If we are using Jython, and the classpath contains one or more spaces, add additional brackets or quotation marks around the classpath. For example:
      (dist)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [['classPath', 'c:/JDBC Driver/test.jar']]])


      (zos)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [['classPath', '/JDBC Driver/test.jar']]])


      (iseries)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [['classPath', 'home/myProfile/JDBC Driver/test.jar']]])

      or
      (dist)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath', "'c:/JDBC Driver/test.jar'"]])


      (zos)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath', "'/JDBC Driver/test.jar'"]])


      (iseries)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath', "'home/myProfile/JDBC Driver/test.jar'"]])

    • Jython, if the classpath contains more than one path, we can use either list syntax, or string syntax delimited by a semicolon to specify the multiple classpaths.

      Use list syntax :
      (dist)

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


      (zos)

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


      (iseries)

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

      Use string syntax delimited by a semicolon:
      (dist)

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


      (zos)

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


      (iseries)

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

    • Jython, if the classpath contains more than one path, and one of those classpaths contain one or more spaces, enclose the path string containing the spaces with quotation marks. For example:
      (dist)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [classPath [test1.jar "C:/JDBC Driver/test.jar" test3.jar]]]')


      (zos)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath [test1.jar "C:/JDBC Driver/test.jar" test3.jar]]]')


      (iseries)

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath [test1.jar "C:/JDBC Driver/test.jar" test3.jar]]]')

    gotcha

    Element Description
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    create is an AdminConfig command
    Library is an attribute
    serv evaluates the ID of the server specified in step number 1
    name is an attribute
    mySharedLibrary is a value of the name attribute
    classPath is an attribute
    /mySharedLibraryClasspath is the value of the classpath attribute
    print is a Jython command

    Example output:

      MysharedLibrary(cells/mycell/nodes/mynode/servers/server1|libraries.xml#Library_1)

  4. Identify the application server from the server and assign it to the appServer variable. For example:

    • Jacl:

        set appServer [$AdminConfig list ApplicationServer $serv]

    • Jython:

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

    Element Description
    set is a Jacl command
    appServer is a variable name
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    list is an AdminConfig command
    ApplicationServer is an attribute
    serv evaluates the ID of the server specified in step number 1
    print is a Jython command

    Example output:

      server1(cells/mycell/nodes/mynode/servers/server1|server.xml#ApplicationServer_1

  5. Identify the class loader in the application server and assign it to the classLoader variable. For example:

    • To use the existing class loader that is associated with the server, the following commands use the first class loader:

      • Jacl:

        set classLoad [$AdminConfig showAttribute $appServer classloaders]
        set classLoader1 [lindex $classLoad 0]

      • Jython:

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

      Element Description
      set is a Jacl command
      classLoad, classLoader1 is a variable name
      $ is a Jacl operator for substituting a variable name with its value
      AdminConfig is an object that represents the WAS configuration
      showAttribute is an AdminConfig command
      appServer evaluates the ID of the application server specified in step number 3
      classloaders is an attribute
      print is a Jython command

    • To create a new class loader, issue the following command:

      • Jacl:

          set classLoader1 [$AdminConfig create Classloader $appServer {{mode PARENT_FIRST}}]

      • Jython:

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

    Element Description
    set is a Jacl command
    classLoader1 is a variable name
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    create is an AdminConfig command
    Classloader is an attribute
    appServer evaluates the ID of the application server specified in step number 3
    mode is an attribute
    PARENT_FIRST is the value of the attribute
    print is a Jython command

    Example output:

      (cells/mycell/nodes/mynode/servers/server1|server.xml#Classloader_1)

  6. Associate the shared library created with the application server through the class loader. For example:

    • Jacl:

        $AdminConfig create LibraryRef $classLoader1 {{libraryName MyshareLibrary}}

    • Jython:

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

    Element Description
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    create is an AdminConfig command
    LibraryRef is an attribute
    classLoader1 evaluates the ID of the class loader specified in step number 4
    libraryName is an attribute
    MyshareLibrary is the value of the attribute
    print is a Jython command

    Example output:

      (cells/mycell/nodes/mynode/servers/server1|server.xml#LibraryRef_1)

  7. Save the configuration changes.

    Use the following command example to save the configuration changes:

      AdminConfig.save()

  8. Synchronize the node.

    Use the syncActiveNode or syncNode scripts in the AdminNodeManagement script library to propagate the configuration changes to node or nodes.

    • Use the syncActiveNodes script to propagate the changes to each node in the cell:

        AdminNodeManagement.syncActiveNodes()

    • Use the syncNode script to propagate the changes to a specific node:

        AdminNodeManagement.syncNode("myNode")


Related tasks

  • Start the wsadmin scripting client
  • Create shared libraries
  • Associate shared libraries with applications or modules
  • Configure a shared library for an application
  • Use the wsadmin scripting AdminConfig object for scripted administration

  • Resource configuration scripts
  • Server settings configuration scripts
  • Commands for the AdminConfig object