3. Installing Java

Download the latest versions of the Java 2 Development Kit (JDK) or Run-time Engine (JRE), and the accompanying documentation from:

  http://java.sun.com

Installation instructions and release notes for the JDK and JRE are available at the download page.

Make the binary distribution of the JDK executable and extract in a new directory:

  
  chmod +x jdk-xxx.bin
  cd /usr/local/
  .../jdk-xxx.bin
  
  

Install the JDK documentation by unzipping it in the JDK directory:

  
  cd /usr/local/jdk-xxx/
  unzip .../jdk-xxx-doc.zip
  
  

Change the ownership of the JDK directory and make it available as /usr/local/j2sdk/:

  
  chown -R root:root /usr/local/jdk-xxx/
  ln -s /usr/local/jdk-xxx /usr/local/j2sdk
  
  

If you need only the JRE, the installation would be like this:

  
  chmod +x jre-xxx.bin
  cd /usr/local/
  .../jre-xxx.bin
  chown -R root:root /usr/local/jre-xxx/
  ln -s /usr/local/jre-xxx /usr/local/j2re
  
  

Warning

Using JDK version 1.5.0 caused our Tomcat server to crash every now and then:

  
  #
  # An unexpected error has been detected by HotSpot Virtual Machine:
  #
  #  SIGSEGV (0xb) at pc=0x4042db3f, pid=11991, tid=16386
  #
  # Java VM: Java HotSpot(TM) Server VM (1.5.0-b64 mixed mode)
  # Problematic frame:
  # V  [libjvm.so+0x3abb3f]
  #
  
  
Upgrading to version 1.5.0-01 seemed to solve these problems.

Note

For the (previously used) BlackDown Java for Linux distribution:

Find yourself a mirror for the BlackDown Java Development Kit at:

  http://www.blackdown.org/java-linux/mirrors.html

There you can download the latest versions of the J2 Software Development Kit (SDK) and Run-time Engine (RE).

Make sure you pick out the right version for the gcc library installed on your system. You can find out the version currently installed by typing:

  
  rpm -q libgcc
  
  

Installation instructions for the Java Development Kit are available as INSTALL-j2sdk and INSTALL-j2re.

Make the binary distribution of the SDK executable and extract in a new directory:

  
  chmod +x j2sdk-xxx.bin
  cd /usr/local/
  .../j2sdk-xxx.bin
  
  

Change the ownership of the J2SDK directory and make it available as /usr/local/j2sdk/:

  
  chown -R root:root /usr/local/j2sdk-xxx/
  ln -s /usr/local/j2sdk-xxx /usr/local/j2sdk
  
  

Do the same for the RE:

  
  chmod +x j2re-xxx.bin
  cd /usr/local/
  .../j2re-xxx.bin
  chown -R root:root /usr/local/j2re-xxx/
  ln -s /usr/local/j2re-xxx /usr/local/j2re
  
  

Since we didn't install the JDK and JRE in our path, we have to add the bin/ directories to our $PATH environment variable. To make sure the Java distributions and classes can be found, we set the $JAVA_HOME and $CLASSPATH variables as well.

For the Bourne shells, create a file /etc/profile.d/java.sh:

  
  if ! echo ${PATH} | grep -q /usr/local/j2sdk/bin ; then
    export PATH=/usr/local/j2sdk/bin:${PATH}
    fi
  if ! echo ${PATH} | grep -q /usr/local/j2re/bin ; then
    export PATH=/usr/local/j2re/bin:${PATH}
    fi
  export JAVA_HOME=/usr/local/j2sdk
  export CLASSPATH=.:/usr/local/j2sdk/lib/tools.jar:/usr/local/j2re/lib/rt.jar
  
  

Set its ownership and access rights:

  
  chown root:root /etc/profile.d/java.sh
  chmod 755 /etc/profile.d/java.sh
  
  

Do the same for C shells, by creating the file /etc/profile.d/java.csh:

  
  if ( "${path}" !~ */usr/local/j2sdk/bin* ) then
    set path = ( /usr/local/j2sdk/bin $path )
    endif
  if ( "${path}" !~ */usr/local/j2re/bin* ) then
    set path = ( /usr/local/j2re/bin $path )
    endif
  setenv JAVA_HOME /usr/local/j2sdk
  setenv CLASSPATH .:/usr/local/j2sdk/lib/tools.jar:/usr/local/j2re/lib/rt.jar
  
  

and setting its ownership and access rights:

  
  chown root:root /etc/profile.d/java.csh
  chmod 755 /etc/profile.d/java.csh
  
  

Now the JDK should be available to everyone on your system.

Tip

You can test the Java engine by typing:

  
  java -version
  
  

or create a file Test.java:

  
  public class Test {
    public static void main(String[] args) {
      System.out.println("Hello world");
      }
    }
  
  

and test the compiler:

  
  javac Test.java
  java Test
  
  

mirror server hosted at Truenetwork, Russian Federation.