Tuesday, April 3, 2012

Configuring WebLogic Server with a Different JVM

If you need to configure WebLogic Server to use a differnt JVM, you need to deal with two environment variables:
  • JAVA_HOME
    •  Specifies the location of the version of Java used to start WebLogic Server
  • JAVA_VENDOR
    • Specifies the vendor of the JVM (i.e., "Sun", "Oracle", etc.)
In this article, we will examine how these two variables interplay and how do you make changes.  In general, JAVA_VENDOR, if found, is used to define JAVA_HOME.  But, setting JAVA_VENDOR to select which JDK to use depends on whether the system have found the JDK you want to use at the time that WebLogic Server was installed.

BEA_JAVA_HOME and SUN_JAVA_HOME

When WebLogic Server installs, if it can find a JRockit JDK and a Sun JDK, it sets the variables BEA_JAVA_HOME and SUN_JAVA_HOME as shown below:

BEA_JAVA_HOME=""
export BEA_JAVA_HOME
SUN_JAVA_HOME="<path_to_jdk>/jdk6"
export SUN_JAVA_HOME

in the setDomainEnv.sh (or .cmd) file.  In our environment, it has only Sun JDK and no JRockit JDK.  So, that's why you see that BEA_JAVA_HOME was set to be "".

The actual JDK that is used is then determined if the JAVA_VENDOR="Sun" (then use SUN_JAVA_HOME) or JAVA_VENDOR="Oracle" (use BEA_JAVA_HOME).

 if [ "${JAVA_VENDOR}" = "Oracle" ] ; then
        JAVA_HOME="${BEA_JAVA_HOME}"
        export JAVA_HOME
else
        if [ "${JAVA_VENDOR}" = "Sun" ] ; then
                JAVA_HOME="${SUN_JAVA_HOME}"
                export JAVA_HOME
        else
                JAVA_VENDOR="Sun"
                export JAVA_VENDOR
                JAVA_HOME="<path_to_jdk>/jdk6"
                export JAVA_HOME
        fi
fi

But if the JDKs weren't found on install, setting JAVA_VENDOR doesn't work, and if you want a completely arbitrary JDK, then you have to change the appropriate JAVA_HOME variable.

In the above setDomainEnv.sh, it first tries to use JAVA_VENDOR to determine which JDK to use.  If the user didn't set that before WLS is started, it will use the default (i.e., the only JDK found during installation). If you want to use a JDK not found at installation time, you may need to manually change setDomainEnv.sh to fit your needs.

No comments: