Child pages
  • Java Environment
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 13 Next »

Introduction

This page is based on experience of setting up Java 8 on Ubuntu 14.04.  Much of it may be applicable to other Java versions and distros.

Architecture

First we check which architecture we are running on.

Open a terminal and type the command :

arch

 

The output could be i686 or i386 for a 32 bits system or x86_64 for a 64 bits system.

Environment

This tutorial assume that you have at least one java installed on your system. It has not been tested on an Ubuntu without any installed java. However generalities should apply.

user@machine$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) Server VM (build 25.91-b14, mixed mode)

The previous command shows us that we have a running java on our system. On Ubuntu 14.04 the Java commands are under the /usr/bin directory.

user@machine$ which java
/usr/bin/java

The previous command shows us that we are running a java command from /usr/bin.

However in order to manage multiple version of Java the update-alternatives mechanism has been introduced. It allows multiple "providers" to be installed on the same machine, and configures which is the default. 

This mechanism consists of two directories, /etc/alternatives who contains the symlinks and /var/lib/dpkg/alternatives who contains update-alternatives state information.

Let's see where is the java command:

user@machine$ ls -al /usr/bin/java
lrwxrwxrwx 1 root root 22 Mar 12 2013 /usr/bin/java -> /etc/alternatives/java

As you can see the java command from /usr/bin is a symlink and will be resolved against the java command contained in /etc/alternatives.

user@machine$ file /etc/alternatives/java
/etc/alternatives/java: symbolic link to `/usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java'

The previous command shows us where lies the java command and hopefully the directory /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin contains the real java command.

user@machine$ ls -al /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java
-rwxr-xr-x 1 root root 5730 May 4 10:54 /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java

Now take a look in the file /var/lib/dpkg/alternatives/java:

manual
/usr/bin/java
java.1.gz
/usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-i386/jre/bin/java
1069
/usr/lib/jvm/java-8-openjdk-i386/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-oracle/jre/bin/java
1070
/usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
/usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java
1073

That file teaches us that there are several java command installed on this machine.

Java Layout

Either the Open JDK or the Oracle JDK install their environment below /usr/lib/jvm:

user@machine:/usr/lib/jvm$ ls -al
total 100
drwxr-xr-x 5 root root 4096 Jul 11 12:07 .
drwxr-xr-x 205 root root 53248 Jul 7 09:33 ..
lrwxrwxrwx 1 root root 34 Jul 7 15:33 default-java -> /usr/lib/jvm/ramdisk-java-8-oracle
lrwxrwxrwx 1 root root 41 Jul 7 15:34 .default-java.jinfo -> /usr/lib/jvm/.ramdisk-java-8-oracle.jinfo
lrwxrwxrwx 1 root root 19 Apr 22 19:41 java-1.8.0-openjdk-i386 -> java-8-openjdk-i386
-rw-r--r-- 1 root root 3083 Jul 11 11:49 .java-1.8.0-openjdk-i386.jinfo
drwxr-xr-x 7 root root 4096 Apr 25 12:34 java-8-openjdk-i386
lrwxrwxrwx 1 root root 30 Apr 25 12:39 .java-8-openjdk-i386.jinfo -> .java-1.8.0-openjdk-i386.jinfo
drwxr-xr-x 8 root root 4096 May 4 10:55 java-8-oracle
-rw-r--r-- 1 root root 3135 Jul 11 11:48 .java-8-oracle.jinfo
drwxr-xr-x 2 root root 4096 Apr 25 12:42 openjdk-8
lrwxrwxrwx 1 root root 20 Jul 7 11:46 ramdisk-java-8-oracle -> /media/java-8-oracle
-rw-r--r-- 1 root root 3563 Jul 11 11:47 .ramdisk-java-8-oracle.jinfo

Beyond the various directories, files and links in the /usr/lib/jvm directory several remarks need to be done.

First of all we use the debian layout by using the default-java symlink. Tomcat or Eclipse are tools who use the default-java symlink.

We see int the previous output that the default-java point to a ramdisk-java-8-oracle who is a local symlink who points to another directory.

Second we see .jinfo files, one per JDK installed. in our example three versions of the JDK are installed and we see three respective .jinfo files.

Let's see the content of the .java-8-oracle.jinfo: 

name=java-8-oracle
alias=java-8-oracle
priority=1070
section=main
jre ControlPanel /usr/lib/jvm/java-8-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-8-oracle/jre/bin/java
jre javaws /usr/lib/jvm/java-8-oracle/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-8-oracle/jre/bin/jcontrol
jre jjs /usr/lib/jvm/java-8-oracle/jre/bin/jjs
jre keytool /usr/lib/jvm/java-8-oracle/jre/bin/keytool
jre orbd /usr/lib/jvm/java-8-oracle/jre/bin/orbd
jre pack200 /usr/lib/jvm/java-8-oracle/jre/bin/pack200
jre policytool /usr/lib/jvm/java-8-oracle/jre/bin/policytool
jre rmid /usr/lib/jvm/java-8-oracle/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-8-oracle/jre/bin/rmiregistry
jre servertool /usr/lib/jvm/java-8-oracle/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-8-oracle/jre/bin/tnameserv
jre unpack200 /usr/lib/jvm/java-8-oracle/jre/bin/unpack200
jre jexec /usr/lib/jvm/java-8-oracle/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/java-8-oracle/bin/appletviewer
jdk extcheck /usr/lib/jvm/java-8-oracle/bin/extcheck
jdk idlj /usr/lib/jvm/java-8-oracle/bin/idlj
jdk jar /usr/lib/jvm/java-8-oracle/bin/jar
jdk jarsigner /usr/lib/jvm/java-8-oracle/bin/jarsigner
jdk javac /usr/lib/jvm/java-8-oracle/bin/javac
jdk javadoc /usr/lib/jvm/java-8-oracle/bin/javadoc
jdk javafxpackager /usr/lib/jvm/java-8-oracle/bin/javafxpackager
jdk javah /usr/lib/jvm/java-8-oracle/bin/javah
jdk javap /usr/lib/jvm/java-8-oracle/bin/javap
jdk javapackager /usr/lib/jvm/java-8-oracle/bin/javapackager
jdk jcmd /usr/lib/jvm/java-8-oracle/bin/jcmd
jdk jconsole /usr/lib/jvm/java-8-oracle/bin/jconsole
jdk jdb /usr/lib/jvm/java-8-oracle/bin/jdb
jdk jdeps /usr/lib/jvm/java-8-oracle/bin/jdeps
jdk jhat /usr/lib/jvm/java-8-oracle/bin/jhat
jdk jinfo /usr/lib/jvm/java-8-oracle/bin/jinfo
jdk jmap /usr/lib/jvm/java-8-oracle/bin/jmap
jdk jmc /usr/lib/jvm/java-8-oracle/bin/jmc
jdk jps /usr/lib/jvm/java-8-oracle/bin/jps
jdk jrunscript /usr/lib/jvm/java-8-oracle/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-8-oracle/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-8-oracle/bin/jstack
jdk jstat /usr/lib/jvm/java-8-oracle/bin/jstat
jdk jstatd /usr/lib/jvm/java-8-oracle/bin/jstatd
jdk jvisualvm /usr/lib/jvm/java-8-oracle/bin/jvisualvm
jdk native2ascii /usr/lib/jvm/java-8-oracle/bin/native2ascii
jdk rmic /usr/lib/jvm/java-8-oracle/bin/rmic
jdk schemagen /usr/lib/jvm/java-8-oracle/bin/schemagen
jdk serialver /usr/lib/jvm/java-8-oracle/bin/serialver
jdk wsgen /usr/lib/jvm/java-8-oracle/bin/wsgen
jdk wsimport /usr/lib/jvm/java-8-oracle/bin/wsimport
jdk xjc /usr/lib/jvm/java-8-oracle/bin/xjc
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

As you can see this file contains the description of the each java tool, either jre, jdk or plugin is associated with an a particular command or library.

In case this file doesn't exist, create one with the previous content and adjust the path accordingly.

The priority value needs to be unique among the JVM installations.

The following command shows the installed JVM and their according priority number. 

user@machine$ update-java-alternatives -l
default-java 1073 /usr/lib/jvm/default-java
java-1.8.0-openjdk-i386 1069 /usr/lib/jvm/java-1.8.0-openjdk-i386
java-8-openjdk-i386 1069 /usr/lib/jvm/java-8-openjdk-i386
java-8-oracle 1070 /usr/lib/jvm/java-8-oracle
ramdisk-java-8-oracle 1073 /usr/lib/jvm/ramdisk-java-8-oracle

Choose a priority number who do not collapse an existing one.

Then setup default-java:

cd /usr/lib/jvm
sudo ln -s ramdisk-java-8-oracle default-java
sudo ln -s .ramdisk-java-8-oracle.jinfo .default-java.jinfo

 

 


 


  • No labels