Tuesday 13 September 2011

Edit Glassfish JDK path

I recently downgraded my version of Java to compile code for an old project. When I started my Glassfish domain I recieved an error;

The system cannot find the path specified.

When Glassfish is installed it hard-codes its reference to your JDK location. To fix this problem I ended up having to edit a file named asenv.conf (asenv.bat in Windows). The file is located at: /usr/local/glassfish/config/ (C:\glassfish\config\ in Windows).

I 'vi'd into the file and changed the AS_JAVA attribute to my new JDK location;

vi /usr/local/glassfish/config/asenv.conf
AS_JAVA="/usr/java/jdk1.4/"

In Windows you could use these commands to comment out the old reference and add the new one;

REM set AS_JAVA=C:\Program Files\Java\jdk1.6.0_24\jre/..
set AS_JAVA=C:\Program Files\Java\jdk1.4

Tuesday 6 September 2011

Setting JAVA_HOME and PATH variables in Linux

JAVA_HOME

JAVA_HOME is the directory where your Java JDK is installed. To set this; In a Linux Terminal use the export command to set the variable.

JAVA_HOME=<path-to-java>

If your path is set to /usr/java/jdk1.6.0_24/bin/java, set it as follows:

export JAVA_HOME=/usr/java/jdk1.6.0_24/bin/java

PATH

Set this variable to run Java commands without referencing the absolute location of Java every time i.e. javac MyClass.java rather than /usr/java/jdk1.6.0_24/bin/javac MyClass.java. To do this, also in a terminal append the <path-to-java> to the PATH variable using the export command.

PATH=$PATH:/usr/java/jdk1.6.0_24/bin

To see the changes use the echo command.

echo $JAVA_HOME
echo $PATH