Child pages
  • Oracle JDK
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »

Table of Contents

Introduction

Manual installation of Oracle Java (which is preferred to Open Java, which often doesn't work right) is a bit tedious: one needs to find and download the latest release and manually set up all the path variables.

The PPA from webupd8 developer team simplifies our task and provides us with an installer which does all this for us and enables auto-updates.

Installation

Run the following commands in order to install or update the Oracle Java. The idea is applicable to others JVM.

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

The installer takes a while since it needs to download the latest Java installer from the Oracle site.

Setting Java Environment Variables

To automatically set up the Java 8 environment variables, you can install the following package:

sudo apt-get install oracle-java8-set-default

Below /etc/profile.d there are two files jdk.sh and jdk.csh who contain the environment variables definitions.

Here is the content of jdk.sh:

export J2SDKDIR=/usr/lib/jvm/default-java
export J2REDIR=/usr/lib/jvm/default-java/jre
export PATH=$PATH:/usr/lib/jvm/default-java/bin:/usr/lib/jvm/default-java/db/bin:/usr/lib/jvm/default-java/jre/bin
export JAVA_HOME=/usr/lib/jvm/default-java
export DERBY_HOME=/usr/lib/jvm/default-java/db

Here is the content of jdk.csh:

setenv J2SDKDIR /usr/lib/jvm/default-java
setenv J2REDIR /usr/lib/jvm/default-java/jre
setenv PATH ${PATH}:/usr/lib/jvm/default-java/bin:/usr/lib/jvm/default-java/db/bin:/usr/lib/jvm/default-java/jre/bin
setenv JAVA_HOME /usr/lib/jvm/default-java
setenv DERBY_HOME /usr/lib/jvm/default-java/db

The oracle-java8-set-default package install only those two files. The system will ensure that one those files will be runned when you open a session.

Close and re-open a session and check your environment with a printenv command.

In this tutorial we are using the debian layout who uses default-java. Tomcat is known to use it and as such we ensure that our system is tuned  accordingly. That way our systems will always shows a default-java.

Verification

Make sure something silly didn't happen and your alternatives were set to Oracle Java:

java -version

Expected output (with Oracle Java 8):

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) Server VM (build 25.40-b25, mixed mode)

Wrong output (with OpenJRE)

OpenJDK Runtime Environment (IcedTea6 1.13.6) (6b34-1.13.6-1ubuntu0.12.04.1)
OpenJDK Server VM (build 23.25-b01, mixed mode)

Then

javac -version

Expected output (with Oracle Java 8):

javac 1.8.0_40

(Without Oracle Java, OpenJDK is rarely installed)

If the wrong Java is chosen, run:

update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javaws

and choose Oracle's needed version.

Then run

update-initramfs -u

Troubleshooting

Firewall/cacher

The installer fetches the latest Java binary via wget. Most of the time, the download fails because either the firewall blocks it or because the cacher doesn't allow it. Since Java updates are not very frequent, we can turn off the firewall while installing, but the cacher can at least be configured for a permanent bypass. Create /etc/apt/apt.conf.d/03java-bypass with the following contents:

/etc/apt/apt.conf.d/03java-bypass
Acquire::http::Proxy {
    download.oracle.com DIRECT;
};

This will ensure that downloads from download.oracle.com initiated by pre/post-install scripts do not go through the cacher. The ideal solution would be to make them cached but that needs a regex hack for apt-cacher-ng (to stop it from rejecting this site as a cacheable source) which I was not able to develop yet.

Architecture

If your host architecture differs from LTSP chroot, you won't be able to install Java this way. Chrooting will make the chroot report the host's architecture to the installer, which causes it to download the wrong binary. Generally, chroots should be kept the same architecture as host, but if they must be different, one can still install Java this way if live-boot from the correct architecture media is done and chroot is entered from it.

Browser Plugin

In some cases, the presence of IcedTea Java Browser plugin (OpenJRE implementation) will prevent Oracle Java plugin from working or even being installed.

It is advised to remove all icedtea packages either prior to Oracle Java installation or after it.

In the latter case, reinstallation of Oracle Java might be required to install the plugin properly.

Note: Oracle Java will not work in Google Chrome (since Google changed the plugin implementation system from previous standard) until Oracle issues an updated plugin.

As we see in the the Java Environment Tutorial the .jinfo file contains the plugin support. This tutorial only use the Firefox Java support while Chrome and Chromium do not any more support. However here are some known plugin support on Linux:

plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin firefox-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin iceape-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin iceweasel-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin mozilla-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin midbrowser-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so 
plugin xulrunner-javaplugin.so /usr/lib/jvm/java-8-oracle/jre/lib/i386/libnpjp2.so

Append your .jinfo file with what's needed.

  • No labels