Difference between revisions of "RPi Java JDK Installation"

From eLinux.org
Jump to: navigation, search
 
(4 intermediate revisions by one other user not shown)
Line 3: Line 3:
  
 
=='''Installing OpenJDK on a Raspberry Pi (Debian Wheezy or Rasbian Wheezy)'''==
 
=='''Installing OpenJDK on a Raspberry Pi (Debian Wheezy or Rasbian Wheezy)'''==
OpenJDK based on IcedTea is packaged for both soft and hardfloat systems.
+
OpenJDK based on IcedTea is packaged for both soft and hardfloat systems. Installation of OpenJDK is easy:
 +
 
 
sudo apt-get update
 
sudo apt-get update
 +
 
sudo apt-get install openjdk-7-jdk
 
sudo apt-get install openjdk-7-jdk
 +
 +
==='''Installing IcedTea-web browser plugin and javaws 'jnlp' webstart'''===
 +
OpenJDK support the IcedTea-web browser plugin for using java applets inside the midori browser.
 +
 +
sudo apt-get update
 +
 +
sudo apt-get install icedtea-7-plugin
 +
 +
If you want to compile a java "applet" application against the icedtea-web plugin classes then include
 +
/usr/share/icedtea-web/plugin.jar on the classpath.
  
 
=='''Installing The Oracle Java SE7 JDK on a Raspberry Pi (Debian Wheezy)'''==
 
=='''Installing The Oracle Java SE7 JDK on a Raspberry Pi (Debian Wheezy)'''==
Line 30: Line 42:
  
 
=Installing the software=
 
=Installing the software=
Login to the computer, activate a web browser, and navigate to the [[http://www.oracle.com/technetwork/java/javase/downloads/index.html |Oracle Java SE Downloads]] download page.
+
Login to the computer, activate a web browser, and navigate to the [[http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html |Oracle Java SE Downloads]] download page.
 
[The Midori browser has had trouble interfacing to this page.  This page has been successfully handled using the [[RPi_IceWeasel |Iceweasel]] browser.]
 
[The Midori browser has had trouble interfacing to this page.  This page has been successfully handled using the [[RPi_IceWeasel |Iceweasel]] browser.]
 
Click on the JDK Download link.
 
Click on the JDK Download link.

Latest revision as of 02:15, 16 December 2013

Back to RPi Guides.

Installing OpenJDK on a Raspberry Pi (Debian Wheezy or Rasbian Wheezy)

OpenJDK based on IcedTea is packaged for both soft and hardfloat systems. Installation of OpenJDK is easy:

sudo apt-get update

sudo apt-get install openjdk-7-jdk

Installing IcedTea-web browser plugin and javaws 'jnlp' webstart

OpenJDK support the IcedTea-web browser plugin for using java applets inside the midori browser.

sudo apt-get update

sudo apt-get install icedtea-7-plugin

If you want to compile a java "applet" application against the icedtea-web plugin classes then include /usr/share/icedtea-web/plugin.jar on the classpath.

Installing The Oracle Java SE7 JDK on a Raspberry Pi (Debian Wheezy)

What does it do?

This page shows how to install the Oracle Java SE JDK7 on the Raspberry Pi Debian Wheezy image.

If you want to use Oracle JDK 7 or 8 on a hardflaot "Rasbian" Wheezy image then you need to get the early access version from java.net

Prerequisites

  • A booted Raspberry Pi with keyboard, mouse, monitor
  • A network connection (Ethernet or WiFi).
  • Authorization to use root privileges.

Installing the software

Login to the computer, activate a web browser, and navigate to the [|Oracle Java SE Downloads] download page. [The Midori browser has had trouble interfacing to this page. This page has been successfully handled using the Iceweasel browser.] Click on the JDK Download link. Read and accept the Oracle Binary Code License Agreement for Java SE. Download the current file for "Linux ARM v6/v7 Soft Float ABI" and save in a location where you have write access. Your home directory will be assumed for the following instructions.

The following directions assume that you are installing version 7u10 of the JDK. Adjust the filenames appropriately if you downloaded and are installing a different version.

Activate a terminal window by either double click on either of the "LXTerminal" or "Root Terminal" icons or menu "Accessories -> LXTerminal" or "Accessories -> Root Terminal". Type the following commands in the terminal to create an installation directory and unpack the downloaded file:

sudo mkdir -p /opt/java
sudo chown root:root /opt/java
cd /opt/java
sudo tar xvzf ~/jdk-7u10-linux-arm-sfp.tar.gz

This should create directory /opt/java/jdk1.7.0_10 (or similar, depending on the version you downloaded). If the tar command completes correctly, the downloaded file in your home directory can be deleted:

rm ~/jdk-7u10-linux-arm-sfp.tar.gz

The system needs to know that a JVM has been installed, where it can be found on the system, and which is the default version (if there is more than one choice available). Type the following in the command window:

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_10/bin/java" 1
sudo update-alternatives --set java /opt/java/jdk1.7.0_10/bin/java

Java should now be successfully installed. To test this, request the java version with:

java -version

You should get a response showing the version that you just installed.

java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode)

To use all java programs, you need to define a JAVA_HOME environment variable and add the associated bin directory to the system PATH. Edit the file /etc/environment with an editor of your choice (eg. nano):

sudo nano "/etc/environment"

and add:

JAVA_HOME="/opt/java/jdk1.7.0_10"

Similarly, add the following line in an appropriate place in your ~/.bashrc file:

export JAVA_HOME="/opt/java/jdk1.7.0_10"
export PATH=$PATH:$JAVA_HOME/bin 

This will need to be done for each username on the system.

Create a new command window to see the environment changes you have made in the above files. Type the following:

export

You should see the above definitions in JAVA_HOME and PATH environment variables. If desired, do the same after a reboot.