Novell is now a part of Micro Focus

Setting Java System Variables

Novell Cool Solutions: Tip
By Jesse Pretorius

Digg This - Slashdot This

Posted: 29 Oct 2007


For a project I'm busy with I needed to install a version of the Sun JDK (v1.5 update 12) that was not part of the distribution. After the installation I needed to find a quick and easy way to ensure that the JAVA_HOME and JRE_HOME variables for the system were set properly.


After poking around I found that the script /etc/profile.d/ seems to do all the magic of figuring out where the JRE is and setting the environment variables. In order to make the useful stuff in /etc/profile.d/ work its magic (so that I didn't have to) I had to setup a symbolic link as follows:

    mkdir /usr/lib/jvm
    ln -s /usr/java/jdk1.5.0_12 /usr/lib/jvm/java

Once that was done, the JAVA_HOME and other environment variables were all setup nicely. However, after doing some more work I found that the PATH hadn't been setup to include the $JRE_HOME/bin directory.

After looking through /etc/profile.d/ I found the problem. In lines 21-23 you can see the logic that checks for the presence of a JRE and sets up the JRE_HOME environment variable.

    if [ -x /usr/$__libdir/jvm/java/jre/bin/java ] ; then
        export JRE_HOME=/usr/$__libdir/jvm/java/jre

In order to also change the PATH environment variable simply add an extra "export" statement before the "else" so that those lines now read:

    if [ -x /usr/$__libdir/jvm/java/jre/bin/java ] ; then
        export JRE_HOME=/usr/$__libdir/jvm/java/jre
        export PATH=$PATH:/usr/$__libdir/jvm/java/jre/bin

Once that's done, everything works much like it would have if you were using a distribution-based version of the JVM.



Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates