Contributions

Contributions are appreciated and used to host this site. Thank You for your support.

Feature Products
  • Raspberry Pi with Java: Programming the Internet of Things (IoT)
    Raspberry Pi with Java: Programming the Internet of Things (IoT)
  • Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
    Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
  • Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
    Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
  • Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
    Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
  • Getting Started with Raspberry Pi
    Getting Started with Raspberry Pi
  • Raspberry Pi User Guide
    Raspberry Pi User Guide
  • PiBrella LED Add On Board
    PiBrella LED Add On Board
  • Diversitech® WS-1 - Wet Switch Flood Detector
    Diversitech® WS-1 - Wet Switch Flood Detector
  • Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
    Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
  • Floodstop Washing Machine Valve Shutoff Kit
    Floodstop Washing Machine Valve Shutoff Kit
  • Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
    Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
  • Floodstop Individual Water Appliance Additional Water Sensor XS-01
    Floodstop Individual Water Appliance Additional Water Sensor XS-01
  • Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
    Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
  • Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Metra 70-2002 Radio Wiring Harness for Saturn 00-05
    Metra 70-2002 Radio Wiring Harness for Saturn 00-05
  • Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
    Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
Thursday
Aug162012

Raspberry Pi - Installing Oracle Java Runtime Environment (JRE 1.7.0u4 Embedded)

The Raspberry Pi is an inexpensive little ARM-based embedded computer developed as a teaching and experiment platform.  I wanted to experiment running Java applications on my Raspberry Pi so I need to install a Java Runtime to execute Java-based applications.  

I first installed the Open JDK on the device since this is the JRE flavor most commonly found in mainstream Linux OS distributions.   Installing the Open JDK is quite simple.  All you have to do is enter the following command and it will download and install the Open JDK.  

apt-get install openjdk-6-jdk

However, the performance I experienced while using the Open JDK on the Raspberry Pi was quite disappointing and dare I say unusable for any reasonably sophisticated Java program.  ChrisG posts some pretty revealing benchmarks using various JVMs in this blog article:  http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=6369   I ran the same benchmark tests on my Pi and got very similar results.  If you notice the Oracle JRE benchmark results in ChrisG's post you will see that they are an order of magnitude better in performance than the Open JDK Zero and Open JDK Cacao JVMs.  For my goals, this make the Oracle JVM the only suitable candidate for running my Java applications.  

This article will provide the necessary instructions on how to install the Oracle Java Runtime Environment on your Raspberry Pi.  

Prerequisites

  • Install and boot the Raspberry Pi using the Debian "Wheezy" (2012-08-08 soft-float) image.  (or the older Debian "Squeeze" (2012-04-19) image
    (The Oracle JRE is not currently compatible with the Raspian "Wheezy" image
  • Enable the Raspberry Pi for SSH remote network connections.  
    Update:  The Debian "Wheezy" image comes with SSH access enabled in the default image.
    (Here is an article on how to enable SSH in the Debian Squeeze distribution)
  • Get the Raspberry Pi's IP address.

Tools & Downloads:

All:

Windows:

Mac-OSX:

Download the Oracle JRE for the Raspberry Pi

You can download the Oracle Java SE Embedded 7 JRE for ARMv6/7 Linux - Headless on this page:
http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html

Please note that you do unfortunately have to fill out a survey to download the JVM.  This means that you cannot simply use a tool such as wget or curl to download the JVM directly to the Raspberry Pi. (oracle-fail!)  Well I guess you could technically run "startx" and use a graphical browser in the X-Windows GUI to complete this step, but this article will use SCP to get the JVM file transferred to the Raspberry Pi.

Transfer the Oracle JRE to the Raspberry Pi

After downloading the Oracle JRE to you desktop computer, we need to transfer it over to the Raspberry Pi.  We will use SCP to transfer the file over the network.  If you are running on a Windows desktop, then download and install WinSCP.

 If you are using Mac OSX, you can download and install Cyberduck.  The screens will look different but the goals are the same.

Create a new session in WinSCP using the IP address of you Raspberry Pi.  The default authentication credentials for the Debian Squeeze image is username "pi" and password "raspberry".  Save the session and then login.  You may be prompted to accept the SSH fingerprint, choose "Yes" to accept and continue.

After successfully establishing a connection, select the drive and folder location in the left pane where you download the Oracle JRE file to on your local desktop system.  In the right pane is the file system on the Raspberry Pi, we will leave it in it's default location in the "pi" user's home directory.  Drag and drop the Oracle JRE file from the left pane to the right pane and WinSCP will start the file transfer process.  You will be prompted with a transfer dialog, just click the "Copy" button to start the transfer.  


When the file transfer is complete, you can close WinSCP (or CyberDuck).

Installation Procedure on Raspberry Pi

The remaining steps should be performed directly on the console of the Raspberry Pi or using a SSH terminal connection with shell access.  In the last step, we transfered the Oracle JRE file to the "pi" user's home directory.  We should be logged in as the "pi" user and already in the user's home directory.

Lets create a new directory where we will install the JRE files to. 

sudo mkdir -p -v /opt/java

Next, lets unpack the Oracle JRE tar file using this command

tar xvzf ~/ejre-7u4-fcs-b20-linux-arm-vfp-client_headless-12_apr_2012.gz


The unpacking process will take a few seconds to complete.  It unpacks all the contents of the Oracle JRE tar file to a new directory named "ejre1.7.0_04" located in the user's home directory.

With the unpack complete its now time to move the new unpacked directory to the Java install location that we created earlier under "opt/java".  

sudo mv -v ~/ejre1.7.0_04 /opt/java

We can also delete the original taf file as it is no longer needed 

rm ~/ejre-7u4-fcs-b20-linux-arm-vfp-client_headless-12_apr_2012.gz

To complete the JRE installation we need to let the system know there is a new JVM installed and where it is located.  Use the following command to perform this task.

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/ejre1.7.0_04/bin/java" 1

And finally we also need to tell the system that we want this JRE to be the default JRE for the system. The following command will perform this action.

sudo update-alternatives --set java /opt/java/ejre1.7.0_04/bin/java

Now java is installed.  To test and verify we can execute the java command using the version argument.

java -version

You should get the following response:

That's it the Oracle JRE is installed and ready for use.

Add JAVA_HOME Environment Variable

Some Java programs require a JAVA_HOME environment variable to be configured on the system.  Add the following line to you "/etc/environment" or your "~/.bashrc" file using your favorite text editor.

JAVA_HOME="/opt/java/ejre1.7.0_04"

Reboot or re-login to apply the export to your environment.  

Coffee & Pie  - what could be better!  

Demo Video 

Hinkmond Wong and Gary Collins of Oracle are going to introduce you to developing for the Raspberry Pi using Java Embedded technology.

In addition to demoing the Raspberry Pi running Java Embedded, they will cover:

  • What is Java SE Embedded?
  • Developing with Java for Embedded
  • Best practices w/ Java for Embedded 
  • Downloading and installing Java SE Embedded Platform

* Raspberry Pi is a trademark of the Raspberry Pi foundation.
* Oracle and Java are registered trademarks of Oracle.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments (5)

I am not naive, but it seems to me there is one extra "not" in the paragraph describing the scp to the pi:
"we not need to transfer "
CU,
Thomas

April 12, 2013 | Unregistered CommenterThomas

@Thomas,

Thanks for the correction. I have updated the article.

April 12, 2013 | Registered CommenterRobert Savage

Installing Java is one of the tougher tasks, my reading this article installing JAVA is quite petite. Thanks for sharing the post.

Participate in the lowes customer satisfaction survey portal at the official survey portal. Here is the lowes.com online survey portal, take the lowes survey now and share all your valuable thoughts at lowescomsurvey.com.co official portal. Enter the survey now and enter the sweepstakes for a chance to win $500 check. Take survey now; thanks - regrads.

March 21, 2024 | Unregistered CommenterJordan

The Home Depot is a well-known American home improvement retailer with over 2,200 stores across the United States. The Homedepot offers a wide range of products for DIY enthusiasts, contractors, and professionals, including tools, appliances, building materials, and more. The Home Depot store aims to provide a one-stop shop for all home improvement needs, with knowledgeable staff and quality products. The store also offers a customer satisfaction survey, allowing customers to provide feedback on their shopping experience. The survey helps the company improve its services and products, ensuring customer satisfaction and loyalty. Customers can participate in the survey online at the Home Depot Survey Portal, sharing their opinions and suggestions for a better shopping experience at The Home Depot. A $5000 Home Depot Gift Card is awaiting the Home Depot Customers who finished the survey.

March 22, 2024 | Unregistered CommenterJenny

The Kroger Customer Experience Survey, often referred to as the Kroger Feedback Survey, is an official online platform where customers can provide feedback about their recent shopping experience at Kroger stores. The primary purpose of this survey is to gather customer opinions on various aspects of their visit, helping Kroger improve its products, services, and overall customer satisfaction. You need a valid receipt from a Kroger store purchase. The receipt contains a date, time, and a survey entry ID needed to access the survey. Internet Access: A smartphone, tablet, or computer with an internet connection. Age Requirement: Participants must be at least 18 years old. Language Options: The survey is available in English and Spanish

November 11, 2024 | Unregistered CommenterPaW1

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Raspberry Pi - Installing a RS232 Serial Port | Main | Raspberry Pi - Enabling SSH for Remote Access »