Raspberry Pi - Installing Oracle Java Development Kit (JDK 1.7.0u6)
The Oracle JDK for ARM is now available! This article will provide the necessary instructions on how to install the Oracle Java Development Kit (JDK) on your Raspberry Pi.
Prerequisites
- Install and boot the Raspberry Pi using the Debian "Wheezy" (2012-08-08 soft-float) image.
(The Oracle JDK 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:
- Raspberry Pi Debian "Wheezy" image (2012-08-08)
- Oracle Java SE Development Kit (Select JDK Download, then Linux ARM - jdk-7u6-linux-arm-sfp.tar.gz)
Windows:
Mac-OSX:
Download the Oracle JDK for the Raspberry Pi
You can download the Oracle Java SE Development Kit 7u6 on this page:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
First, select JDK Download button under JDK SE 7, then select the LinuxARM JDK7 SE distribution (jdk-7u6-linux-arm-sfp.tar.gz).
Transfer the Oracle JDK to the Raspberry Pi
After downloading the Oracle JDK 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 JDK 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 JDK 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 JDK 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 JDK files to.
sudo mkdir -p -v /opt/java
Next, lets unpack the Oracle JDK .gz file using this command
tar xvzf ~/jdk-7u6-linux-arm-sfp.gz
The unpacking process will take a few seconds to complete. It unpacks all the contents of the Oracle JDK tz file to a new directory named "jdk1.7.0_06" 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 ~/jdk1.7.0_06 /opt/java
We can also delete the original .tz file as it is no longer needed
rm ~/jdk-7u6-linux-arm-sfp.gz
To complete the JDK 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/jdk1.7.0_06/bin/java" 1
And finally we also need to tell the system that we want this JDK to be the default Java runtime for the system. The following command will perform this action.
sudo update-alternatives --set java /opt/java/jdk1.7.0_06/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 JDK 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" using your favorite text editor.
JAVA_HOME="/opt/java/jdk1.7.0_06"
Also, edit your "~/.bashrc" file using this command
nano ~/.bashrc
and add the following two lines to the bottom of the file and save.
export JAVA_HOME="/opt/java/jdk1.7.0_06"
export PATH=$PATH:$JAVA_HOME/bin
Reboot or re-login to apply the export to your environment.
* Raspberry Pi is a trademark of the Raspberry Pi foundation.
* Oracle and Java are registered trademarks of Oracle.
Reader Comments (36)
Thanks a lot for writing this up! I'm looking forward to getting into the thick of things, when my board finally arrives. :)
Quick aside, the Oracle download above under Tools & Downloads is hinted at in your post as jdk-7u6-linux-x64.tar.gz, while further down you reference the sfp one.
Cheers! Will look for more raspi+java here in the future, leeching your expertise. :P
@Ben
Great catch! I updated the article to correct the jdk sfp reference.
I am currently working on Java controlling the RasPi's GPIO. There is a current Java library working (http://code.google.com/p/rpi-gpio-java/downloads/list), but it does not provide pull-up/pull-down configuration and it does not provide callback notification on GPIO pin state changes, so I am hoping to create a library that can also accomplish those goals. I will probably based it on the wiringPi project. (https://projects.drogon.net/raspberry-pi/wiringpi/). Stay tuned for more :-)
It works perfectly!!!
Very detail and useful post!
thanks a lot!!
@Kenny,
You are welcome; happy to hear it is helpful information :-)
I followed the instructions but I'm getting an error:
$ java -version
java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
I did have OpenJDK installed before but I removed that first before doing the Oracle JDK.
@Leon
If you get the "libjli.so" error, it is most likely that you are trying to use the Oracle JDK on a hard-float OS image such as Raspian. Unfortunately at this time the Oracle JDK only works on soft-float images (such as Debian Wheezy). Oracle has confirmed that they are working on a hard-float version, but no information on when that can be expected is available at this time.
Hello
Could this library work on a BeagleBone?
Thank you in advance for the answer.
Hi,
I think that 've exactly followed the instructions, but when I arrive at the end to test the java intall via "java -version", it tells me:
-bash: java: command not found
also I didn't have the bin/java folder in /opt/java/jdk1.7.0_06/bin/java and had to create them manually... they're empty...
is this normal?
Well mystery solved... I didn't expand the partitions on the SD card after the install and apparently I ran out of space when I tried to unpack the Java package...
@Vlad
I'm not sure about the specific instructions for installing the Oracle JVM on the BeagleBone. I'm pretty sure the JDK is capable of running on that platform, but I don't have one to try out ... sorry.
@Daniel
Glad to see you got it figured out. I was scratching my head after reading your first post thinking that a copy step was missed, but running out of drive space certainly makes sense. In fact, I think I ran into the same problem early on when I first received my Pi.
Do you have any idea why the jboss eap 6.0.0 won't start with this jdk?
It's sfp, I've had it running using the sfp jre7, but this jdk won't work:
"Error occurred during initialization of VM
Server VM is only supported on ARMv7+ VFP"
@Daniel,
Are you using some script to try to start JBoss? You may need to try editing the script and looking for the location where it calls the java program. Basically, the JVM support a "-server" argument that will tune the JVM for server applications. However, this is not supported on the Raspberry Pi / ARMv6. Try removing the "-server" argument from the startup script.
The next thing you will have to contend with is the limited amount of memory. I have not used JBoss on en embedded system so not sure how much RAM is will want to chew up. If you are not using the GUI on the Pi, make sure to run "sudo raspi-config" and set the "memory-split" option to provide the least amount of RAM to the VideoCore. This will free up more memory for your applications.
Yeah, I'm using the jboss 6.0.0 package which can be downloaded @ redhat.
It has a predefined standalone.sh which is used to start the jboss server. I'll try to find where to change the server/client argument.
I'm using a 512MB RPi with a start.elf which sets the memory split to 496/16
I think that should be enough
Thanks for your help!
hi
Wonderful guide
Does can access to serial port or is need some extras like or similar:
http://www.cloudhopper.com/opensource/rxtx/
best regards
@Luca,
To access the serial port from a Java program, yes you do need some external library. RXTX is a very popular library for Linux based systems. You'll need a RXTX port for ARM. Alternatively if you just need something for simple serial communications, there is also the Pi4J project which provides basic serial communication for Java programs. Visit www.pi4j.com for more info.
Thanks, Robert
many thanks for the suggestions and for the fast response.
Have You personally tried one ore both?
talking about RXTX port for ARM
We must to compile it or we can find it for download directly?
(I did not find)
best regards
luca
@Luca,
I am currently using Pi4J for my serial communication needs from the RaspberryPi.
http://pi4j.com/example/serial.html
I have not personally tried RXTX on the Pi but I have used it in on other platforms. However, here is a great article on using RXTX and Raspberry Pi.
http://eclipsesource.com/blogs/2012/10/17/serial-communication-in-java-with-raspberry-pi-and-rxtx/
According to this article, it looks like you can get it (precompiled) from one of the Debian apt-get repositories.
Good Luck!
-Robert
this is amazing! thank you very much for your help
if I can I take advantage of your skills and your patience
I have another question for you...
I am also free to use external libraries like ordinary pc
and where I should put (the path)
and do you think it have some sense Tomcat on Raspberry
sincerely
Luca
@Luca,
I have not run Tomcat but it is probably possible especially with the newer 512 MB RAM Raspberry Pi hardware. I have run Apache Karaf on the 256MB RAM Raspberry Pi just fine with its web console which is based on Jetty I believe. I was using the Oracle JVM and Debian Wheezy soft-float distribution at the time I was last testing Karaf. The start time was somewhat slow, but once up and running it seemed fine as long as the web app and usage load is not too intensive.
Thanks,
Robert
Hi
thanks for reporting I have ordered 256MB RAM Raspberry Pi and it will arrive in 3 weeks!
I'm trying to install Tomcat without success for now :-(
would also be interesting discuss about protocols to be conveyed to the serial port such as modbus.** canbas DMX etc..
(as Master)
and if it is possible to find ARM libraries for java
for the hardware part I believe that we need CD4050 and a MAX232
thank you very much
Luca