WAS v8.5 > Script the application serving environment (wsadmin) > Configure applications using scripting

Configure a shared library using scripting

We can 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 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

    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:

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

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

    • 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, add additional brackets or quotation marks around the classpath. For example:
      print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [['classPath',  
      'c:/JDBC Driver/test.jar']]])
      or
      print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], ['classPath',  
      "'c:/JDBC Driver/test.jar'"]])
    • Using 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.

      Using list syntax :

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

      Using string syntax delimited by a semicolon:

        print AdminConfig.create('Library', serv, [['name', 'mySharedLibrary'], [classPath,'test1.jar;test2.jar;test3.jar']])
    • Using 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:

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

    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

    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 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]

    • 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']])

    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']])

    Example output:

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

  7. Save the configuration changes.

    Use the following command example to save your configuration changes:

      AdminConfig.save()


Related


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


Reference:

Resource configuration scripts
Server settings configuration scripts
Commands for the AdminConfig object using wsadmin.sh


+

Search Tips   |   Advanced Search