Using a shared library of JNDI properties

You can create a shared library to hold different configurations for any MobileFirst Server component.

If you do not want to inject properties into web archive files, the property file can be installed as a shared library for all MobileFirst Server components. This approach is useful when you intend to exchange the web archive files often, but want to keep the same configuration all the time. The original web archive files remain unchanged, but you need to install an additional shared library.

You can add several different configurations to the same shared library and then select in the web application server which configuration to use. For example, you could have a test configuration and a production configuration injected at the same time. To do so, create property files with different settings, one named testconf.properties and the other prodconf.properties.

Creating a shared library of JNDI properties

The wljndiinject command line tool is used to create a shared library for a set of property files. To create a shared library named jndiprops.jar with the property files testconf.properties and prodconf.properties, use the following command:
wljndiinject --sharedJar --destFile jndiprops.jar testconf.properties prodconf.properties
Options of the tool:
--help
Shows the help.
--sourceWarFile file
This option is not required for creating a shared library. This option is used when a property file is injected into a web archive file to identify the web archive file.
--destFile file
The destination file name of the shared library.
--sharedJar
Used to create a shared library instead of injecting a property file into a web archive file.

Installing a shared library of JNDI configurations

Assume that all web applications are already installed. The shared library is added to the web applications.
WebSphere® Application Server full profile
Determine a suitable directory for the shared library jndiprops.jar in the WebSphere Application Server installation directory and place the jndiprops.jar file there.
  • For a stand-alone server, you can use a directory such as:

    $WAS_INSTALL_DIR/optionalLibraries/IBM/Worklight

  • For deployment to a WebSphere Application Server ND cell, use for example:

    $WAS_INSTALL_DIR/profiles/profile-name/config/cells/cell-name/Worklight

  • For deployment to a WebSphere Application Server ND cluster, use:

    $WAS_INSTALL_DIR/profiles/profile-name/config/cells/cell-name/clusters/cluster-name/Worklight

  • For deployment to a WebSphere Application Server ND node, use:

    $WAS_INSTALL_DIR/profiles/profile-name/config/cells/cell-name/nodes/node-name/Worklight

  • For deployment to a WebSphere Application Server ND server, use:

    $WAS_INSTALL_DIR/profiles/profile-name/config/cells/cell-name/nodes/node-name/servers/server-name/Worklight

For details about adding the shared library, see Adding the shared library (WebSphere Application Server full profile).

WebSphere Application Server Liberty profile
Place the jndiprops.jar file in a suitable directory; for example,$LIBERTY_HOME/usr/shared/resources/lib/jndiprops.jar.

Edit the $LIBERTY_HOME/usr/servers/worklightServer/server.xml file. For each <application> element, add or update the <classloader> element.

<application ...>
    ...
    <classloader delegation="parentLast"></p>
        ...
        <privateLibrary>
            <fileset dir="${shared.resource.dir}/lib"
               includes="jndiprops.jar"/>
        </privateLibrary>
    </classloader>
</application>

Restart the web application server after these changes.

Apache Tomcat
Place the shared library, jndiprops.jar file, in a suitable directory; for example, $TOMCAT_HOME/Worklight/jndiprops.jar.

Edit the $TOMCAT_HOME/conf/server.xml file. For each <Context> element, add or update the <Loader> element.

<Context docBase="worklightconsole" path="/worklightconsole">
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
       virtualClasspath="${catalina.base}/Worklight/jndiprops.jar"
       searchVirtualFirst="true"/>
    …
</Context>

For the MobileFirst project, which uses additional shared libraries, the example code is:

<Context docBase="worklightconsole" path="/worklight">
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
       virtualClasspath="${catalina.base}/Worklight/worklight/worklight-jee-library.jar;${catalina.base}/Worklight/jndiprops.jar"
       searchVirtualFirst="true"/>
    …
</Context>

Restart the web application server after these changes.

Selecting the configuration in a shared library of JNDI configurations

The default configuration is called default.properties. If the configuration of JNDI properties has a different name, you must define the ibm.worklight.jndi.configuration property. The value of this property must be the configuration name without the extension .properties. This property can be specified as a Java™ Virtual Machine system property or explicitly as a JNDI property. This property cannot be defined in the configuration property file.
WebSphere Application Server full profile
You must log in to the WebSphere Application Server administration console and add the setting of the ibm.worklight.jndi.configuration property to the Java Virtual Machine custom properties.

To add this property setting:

  1. Select Servers > Server types > WebSphere Application Servers.
  2. Select the name of your server.
  3. Expand "Java and process management" and select "Process Definition"
  4. Select "Java Virtual Machine".
  5. Select "Custom Properties" and click New.
  6. Specify the name as ibm.worklight.jndi.configuration.
  7. Specify the value as the name of the configuration.
  8. Click Apply.
  9. Click Save.

When the property is set, to enable the configuration, restart the appropriate MobileFirst Server components. These components are displayed in the WebSphere Application Server administration console under WebSphere enterprise applications.

WebSphere Application Server Liberty profile
You must edit the $LIBERTY_HOME/usr/servers/worklightServer/bootstrap.properties file and set the ibm.worklight.jndi.configuration property to point to the name of the configuration.

For example:

ibm.worklight.jndi.configuration=testconf

Alternatively, instead of editing the bootstrap.properties file, create or edit the $LIBERTY_HOME/usr/servers/worklightServer/jvm.options file. For example, add:

-Dibm.ibm.worklight.jndi.configuration=testconf

To enable the configuration, restart the web application server.

Apache Tomcat
You must edit the $TOMCAT_HOME/conf/catalina.properties file and set the ibm.worklight.jndi.configuration property to point to the name of the configuration. For example:
ibm.worklight.jndi.configuration=testconf

Alternatively, instead of editing the catalina.properties file, depending on the operating system, create or edit one of the following files:

  • On UNIX systems: $TOMCAT_HOME/bin/setenv.sh
    For example, add:
    CATALINA_OPTS="$CATALINA_OPTS -Dibm.worklight.jndi.configuration=testconf"
  • On Microsoft Windows systems: $TOMCAT_HOME/bin/setenv.bat
    For example, add:
    set CATALINA_OPTS=%CATALINA_OPTS% -Dibm.worklight.jndi.configuration=testconf

To enable the configuration, restart the web application server.