Revision 133 as of 2011-12-24 12:53:11

Clear message

Introduction

Java is a technology from Oracle (former: Sun Microsystems). There are several implementations, of which five will be discussed here:

  • OpenJDK: The primary goal of the OpenJDK project is to produce an open-source implementation of the Java SE Platform (6 and 7). This is the default version of Java that Ubuntu uses and is the easiest to install.

  • Sun Java: Sun Java is the reference implementation for Java 6.

  • Oracle Java: Oracle Java is the reference implementation for Java 7.

  • IBM Java: IBM Java is the preferred Java solution on PowerPC machines. It is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website.

  • GNU Compiler: A Java compiler made by GNU. Only developers should have to install this.

OpenJDK

Installation of Java Runtime Environment

  • Install the openjdk-6-jre package using any installation method.

Browser plugin

This plugin works with the main browsers: Firefox, Chromium, Google Chrome, and Epiphany.

On Konqueror, go to Settings → Configure Konqueror... and from menu select Java & JavaScript, then tick Enable Java globally option.

SDK (Software Development Kit)

  • Install the openjdk-6-jdk package using any installation method.

Oracle (Sun) Java 6

Oracle (Sun) Java 6 is no longer available to be distributed by Ubuntu. It is recommended that users either migrate to OpenJDK, or install Oracle (Sun) Java 6 manually, or switch to Oracle Java 7. Older versions of Oracle (Sun) Java 6 that have been distributed in the past are vulnerable to security exploits, see this announcement for more information.

If you wish, you can still install the newest and secure Oracle (Sun) Java 6 quite easily, either manually or by using a third-party repository.

By hand: http://sites.google.com/site/easylinuxtipsproject/java

Third-party repository: http://www.duinsoft.nl/packages.php?t=en

Oracle Java 7

Oracle Java 7 is probably at this time not as fit for general use, as openJDK and Oracle (Sun) Java 6. Not yet, anyway.

Currently there are no .deb packages available for Oracle Java 7. The raw binaries (without installer) can be downloaded directly from Oracle (Oracle Java download page).

Installing Oracle Java 7 from the command line

Unfortunately Oracle Java 7 binaries must be manually installed in order to properly setup Java 7 on Ubuntu. There are lot of instructions in the Internet how to install them. Today most comprehensive solutions are:

There is also an RFE opened on Oracle bugtracker to provide the debian package/installer for Java 7. Please consider voting for this RFE.

Choosing the default Java to use

If your system has more than one version of Java, configure which one your system uses be entering the following command in a terminal window

sudo update-alternatives --config java

IBM Java (PowerPC)

IBM Java is the preferred Java version on the PowerPC architecture (OpenJDK is available on PowerPC, but it is rather slow.) IBM produces a Java Development Kit (JDK) for its POWER computers, which happens to also work on PPC. The recent versions of IBM's Java are versions 1.5.0 (version 5) and 1.4.2 (version 4) of Java.

The 1.4.2 JDK is known to work on G3, G4, and G5 Macs, as well as older 604e and 603e Macs. The 1.5.0 JDK is known to work on G3, G4, and G5 Macs, and it is not yet known whether it works on older 604e and 603e Macs. Both also work on non-Mac PowerPCs like the EFIKA. Please update this page if you have more information!

The easiest way is to add the medibuntu-repository to your sources.list.

sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update

After that, you can install the 'ibm-j2sdk1.5' package using any installation method.

Another way to install IBM Java is to go to the IBM WebSphere Application Server Community Edition from SourceForge for both x86 and PowerPC -http://sourceforge.net/powerbar/websphere/download.php.

To use the TGZ with Ubuntu, you have to convert it to a DEB. Make sure you have the tool make-jpkg installed.

        cd ~/Desktop
        sudo dpkg -i java-package_0.27_all.deb

Now convert the 1.4.2 TGZ and install the resulting DEB:

        make-jpkg IBMJava2-SDK-142.ppc.tgz
        sudo dpkg -i ibm-j2sdk1.4_1.4.2_powerpc.deb

Now convert the 1.5.0 TGZ and install the resulting DEB:

        make-jpkg ibm-java2-sdk-50-linux-ppc.tgz
        sudo dpkg -i ibm-j2sdk1.5_1.5.0_powerpc.deb

Note: The latest version (as of February 1, 2007) of the IBM 1.5 SDK, SR4, is called ibm-java2-sdk-5.0-4.0-linux-ppc.tgz. When I tried to install it on Edgy, it returned a No matching plugin found. error. I was able to install it successfully by renaming the downloaded file to match the name ibm-java2-sdk-50-linux-ppc.tgz before running the make-jpkg command.

Note on libraries: the IBM Java binaries depend on libstdc++5 and libgtk1.2 packages. In Dapper and later it's possible that these libraries are not installed because they've been replaced by libstdc++6 and libgtk2.0. In this case, make-jpkg will give a lot of warnings about not being able to find dependencies for library files. To get the dependencies set correctly (and to get the Java to work at all), make sure you have installed libstdc++5 and libgtk1.2 (either by using Synaptic or from the command line) before issuing the make-jpkg command.

To set the new JRE or JDK as the default, you may need to update your Java alternatives. To check your current default, run:

java -version

If you're not happy with what you see, run the following command and, when prompted, choose your preferred Java environment from the list. If update-alternatives tells you that there is only one Java environment, then you'll need to install another version to make a change. If you chose to install both 1.4.2 and 1.5.0 versions, you may run this command at any time to switch the one subsequently opened Java applications will use. The one that the Firefox and Opera web browsers use will be unaffected. Which one the Konqueror web browser uses, and whether or not it would be affected, depends on your KDE system settings.

        sudo update-alternatives --config java

If you installed a 1.4.2 version, regardless of whether or not you installed a 1.5.0 version, and your processor is not a G5, you must perform yet another step to get it to work. For a G3 or G4, use the following command:

        sudo sh -c 'echo "JITC_PROCESSOR_TYPE=6" >> /etc/environment'

For a 604e or 603e, instead use:

        sudo sh -c 'echo "JITC_PROCESSOR_TYPE=5" >> /etc/environment'

You may have to log out or restart the computer for this to take effect.

Note: In the GNOME environment of Ubuntu 6.06 LTS/Dapper Drake, it may be possible that changing language selections may overwrite this file, causing a 1.4.2 version of IBM Java to stop working completely. Please share such experiences, if any, on this wiki.

IF you installed the JDK, the following code tests that everything's working. Open a terminal, and try this for version 1.4.2:

        cd /usr/lib/j2sdk1.4-ibm/demo/applets/TicTacToe
        ../../../bin/appletviewer example1.html

To try version 1.5.0:

        cd /usr/lib/j2sdk1.5-ibm/demo/applets/TicTacToe
        ../../../bin/appletviewer example1.html

If you see a Tic Tac Toe game, it worked! If you installed the JRE, you don't have an appletviewer or any demos so try whichever program it was that led you to install java in the first place!

Neither the Firefox web browser nor the full Mozilla suite can use version 1.4.2, but they can use 1.5.0 if you configure as follows:

        mkdir -p ~/.mozilla/plugins
        cd ~/.mozilla/plugins
        ln -s /usr/lib/j2sdk1.5-ibm/jre/bin/libjavaplugin_oji.so

To control which Java the Konqueror web browser uses, go to your KDE system settings. Select Internet & Network -> Web Browser -> Java & JavaScript, and change the Path to Java executable to either /usr/lib/j2sdk1.4-ibm/bin/java or /usr/lib/j2sdk1.5-ibm/bin/java.

To control which Java the Opera web browser uses, go to Tools -> Preferences -> Advanced -> Content -> Java options, and change the path to either /usr/lib/j2sdk1.4-ibm/jre/bin or /usr/lib/j2sdk1.5-ibm/jre/bin.

Test the installation at the Sun Java test webpage.

GNU Compiler for Java

Install the java-gcj-compat-headless package using any installation method.

To install the development environment, install the java-gcj-compat-dev package using any installation method.

GCJ is a front end to the GCC compiler which can natively compile both Java(tm) source and bytecode files. The compiler can also generate class files. Gcjwebplugin is a little web browser plugin to execute Java applets.

It is targeted for Mozilla and compatible browsers that support the NPAPI. Others include the Eclipse Java Compiler, which is maintained by the Eclipse Foundation. Eclipse is an open-source Integrated development environment (IDE) written primarily in Java. The Eclipse open source community has over 60 open source projects. OpenJDK is the open source Java, derived from sources which will become OpenJDK 7 in the future.


CategorySoftware