Before you start:
First check if the distribution has changed to have a package installation of open java – Perform:
1 2 3 4 5 6 |
root@beaglebone:~# uname -a Linux beaglebone 3.8.11 #1 SMP Wed May 8 07:34:27 CEST 2013 armv7l GNU/Linux root@beaglebone:~# opkg update Downloading http://feeds.angstrom-distribution.org/feeds/v2012.12/ipk/eglibc/armv7a-vfp-neon/base/Packages.gz. Inflating http://feeds.angstrom-distribution.org/feeds/v2012.12/ipk/eglibc/armv7a-vfp-neon/base/Packages.gz. ... |
And see the output after you search for java
1 2 3 4 5 6 7 8 9 10 11 12 |
root@beaglebone:~# opkg list|grep java libbcel-java - 5.2-r0 - bcel version 5.2-r0 libjavascriptcoregtk-1.0-0 - 1.8.2-r2.19 - webkit-gtk version 1.8.2-r2 libjavascriptcoregtk-1.0-0 - 1.8.2-r2.13 libjaxp1.3-java - 1.3.04-r0 - jaxp1.3 version 1.3.04-r0 libregexp-java - 1.5-r0 - regexp version 1.5-r0 librhino-java - 1.7r2-r0.1 - rhino version 1.7r2-r0 librxtx-java - 2.2.0-r2.1 - rxtx version 2.2.0-r2 libxalan2-java - 2.7.1-r0 - xalan-j version 2.7.1-r0 libxerces2-java - 2.9.1-r0 - xerces-j version 2.9.1-r0 libxml-commons-resolver1.1-java - 1.2-r0 - xml-commons-resolver1.1 version 1.2-r0 root@beaglebone:~# |
There are libraries and javascript tools, but no core java distribution. Unfortunately, this means a manual install!
Here are the steps for installing the JRE:
Step 1. Download the Embedded JRE to your desktop PC: Go to the java.oracle.com website and under Downloads -> Choose “Java for Developers” (under popular downloads). Choose the option “Embedded Use” and press on Download. You should now have many options. For the Beaglebone Black you need to use “ARM, Linux” and you want the version with Soft Floating Point numbers (SoftFP) – if you have used a hardFP Linux version, choose the appropriate version. I want the Client Compiler version and I want a Headless version, so my version at this point in time is: ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.tar.gz after you have accepted the licence agreement. You may have to create an Oracle user account if you do not already have one. Finally, the file will download to your desktop PC.
Step 2. Copy this to your Beaglebone Black. I use psftp (start command->psftp) from Windows
Figure 1. Uploading the archive to your Beaglebone
This takes about 3 minutes.
Step 3. Move the .gz file to your installation location
1 2 3 4 5 6 7 8 9 10 11 |
root@beaglebone:~# uname -a Linux beaglebone 3.8.11 #1 SMP Wed May 8 07:34:27 CEST 2013 armv7l GNU/Linux root@beaglebone:~# cd root@beaglebone:~# ls Desktop ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.gz root@beaglebone:~# mkdir /usr/java root@beaglebone:~# mv ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.gz /usr/java root@beaglebone:~# cd /usr/java root@beaglebone:/usr/java# ls ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.gz root@beaglebone:/usr/java# |
Step 4. Extract the archive:
1 2 3 4 |
root@beaglebone:/usr/java# tar xzf ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.gz root@beaglebone:/usr/java# ls ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.gz ejre1.7.0_45 |
If you have not set the time on the Beaglebone, ignore the warnings.
Step 5. Set up our environment variables:
1 2 |
root@beaglebone:/usr/java# export PATH=$PATH:/usr/java/ejre1.7.0_45/bin/ root@beaglebone:/usr/java# export JAVA_HOME=/usr/java/ejre1.7.0_45/ |
Step 6. Test if it works:
1 2 3 4 5 |
root@beaglebone:/usr/java# java -version java version "1.7.0_45" Java(TM) SE Embedded Runtime Environment (build 1.7.0_45-b15, headless) Java HotSpot(TM) Embedded Client VM (build 24.45-b08, mixed mode) root@beaglebone:/usr/java# |
Step 7. Write a short program to test everything – Do this on your desktop PC and transfer the compiled class file to your Beaglebone. (Note: if you want to be lazy you can use my Test.class downloaded from here: Test.class)
Figure 2. Write a short Java application on the Desktop Computer
1 2 3 4 5 6 7 8 |
public class Test { /** * @param args */ public static void main(String[] args) { System.out.println("Hello from the BeagleBone Black!"); } } |
Upload this application to your Beaglebone:
Figure 3. Uploading the class file to your Beaglebone
All going well you should get:
1 2 3 4 5 |
root@beaglebone:~# ls Desktop Test.class root@beaglebone:~# java Test Hello from the BeagleBone Black! root@beaglebone:~# |
And all is working.
Step 8. Setting the Environment Variables permanently
Find out your shell using echo $SHELL and so in my case it is /bin/sh, so I have to edit my .profile in my home directory. Export the two environment variables within your .profile and then Java will work even after reboot.
1 2 3 4 5 6 7 |
root@beaglebone:~# echo $SHELL /bin/sh root@beaglebone:~# vi .profile root@beaglebone:~# more .profile export PATH=$PATH:/usr/java/ejre1.7.0_45/bin/ export JAVA_HOME=/usr/java/ejre1.7.0_45/ root@beaglebone:~# reboot |
And Java should work even after reboot.
Hello Dr. Molloy,
first, I would like to thank you for all your tutorials and great effort here. It is really a great help.
I followed the steps and when I am checking version shows exactly same results of step 6.
but when trying “java Test.class” on BBB I get
Error: Could not find or load main class hello.class
is there any specific details for step 7? like how to export or compile? any thing to do with Eclipse on laptop?
or that sounds like something on BBB
also I am wondering if there is a proper way to use the “Remote System” connection for this.
🙂 THANKS again
I found many mistakes in my try 🙂
Test.class is not same name as mine :/
also I needed to have the java file under the default package <- which was not recommended
Now it is running .. and we are waiting for your next tutorial on java & BBB 🙂
In this post and your excellent video tutorial, you are installing the embedded headless version. Could you comment on the reasons for choosing this instead of the full JDK-version. I have used the full installation with no trouble, but of course it is a bit larger.
As an idea for future tutorials, consider instructions for setting up rxtx on BBB, which is not very hard, but requires a little knowledge of virtual cape specification in uEnv.txt and binary library setup of Java.
After my first comment was made, I discovered purejavacomm, which does not need native libraries installation, but is using jna to access the UART.
Hello Dr. Molloy,
I’m really puzzled. I’ve no problem gettig java to run on the beaglebone black, but I can’t find an implementation for com.oracle.deviceaccess.* I would like to reference a GPIOPin from my java code and manupulate it directly. Do you know if this is possible? I’ve looking all over the internet to find an answer.
Regards, Gijs Sijpesteijn
BTW: Thank you for the excellent tutorials. They have helped me a lot.
Hi Gijs,
did you already manage to access GPIO without using JNA?
regards,
Stein
Hi, I tried to install Java based on your article’s method but did’nt work..
Searching on the web i saw another article to install Java on BBB. I tried the method and works!
The another post method may be usefull for other users who are in the same problem and is in the following link:
http://beagleboard.org/project/java/
Best regards.
I’m curious, what was the problem that you encountered, Michael?
Setting $PATH – You lost me (maybe some hidden key-pressing), but after some googling, I used:
user@bbb# nano ./.profile
Entered the $PATH & JAVA_HOME lines as you (Exept I used 1.7.0.51)
and saved it.
user@bbb# shutdown -r now
And
user@bbb# java Test – WORKS
Greate site – Thanks for the excellent tutorials – as a straight Windows-man they really helps.
Looking forward to your Windows CE 7 Tutorial – I can not get it Installed.
http://embeddedsoftwarestore.com/store/em/SearchCommand?storeId=500201&langId=-1&catalogId=500201&action=Keyword&Ntt=beaglebone&N=0&pageSize=10&searchOffset=0&selectedCatNames=Taxonomy|Software&selectedCatParentIds=0&selectedCatIds=100696&refinementOptions=100804_4284248485&cmp=ESS_vendor_Adeneohome
Regards from Denmark
Jacob Carstens
Thanks Jacob,
Derek.
Hi Dr. Molloy,
I am very thankful for your helpful tutorials.
But I have a question for you. How can I call C by Java and otherwise through JNI for programming on BBB?
It means you can create a tutotial about native programming in BBB.
I’m looking forward to responding of you.
Best regards,
Tan Le
Thank you for your good effort, simple and clear steps.
Have installed Java on my BeagleBoard XM, according to 1) your instructions 2) Oracle’s instructions on the Beagleboard site. Still unable to run the Test.class (or any of Oracles demo classes either).Here’s what I get::
Exception in thread “main” java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: Test. Program will exit.
Any ideas?
here’s what I get from: java -version
java version “1.6.0_18”
OpenJDK Runtime Environment (IcedTea6 1.8.2) (6b18-1.8)
OpenJDK Zero VM (build 14.0-b16, mixed mode)
beagleboard:/home/websdr#
even though I installed the jdk1.7.0_51 file from Oracle’s site.
and
beagleboard:~# opkg list_installed |grep java
librhino-java – 1.7r1-r1.6
libswt3.6-gtk-java – 3.6-r0.5
openjdk-6-java – 6b18-1.8-r10.7.6
and
beagleboard:~# which java
/usr/bin/java
Thanks so much for your great site and instructions.
Rob
This error message is displayed when you try to execute a program with a JRE version less than the one the program has been compiled with (e.g. the class is compiled using JDK 1.7 but the JRE you use to launch it is 1.6.)
OK – removed all previous installations of Java and went again by your instructions and from my ssh’d desktop logged in to the BB I get this::
.
.
beagleboard:~# java -version
sh: java: Permission denied
.
. and from the BB directly as root I get this::
sh: java not found
thanks Rob
Hi Derek,
Great Tutorials. Present from heaven.
I tried you java installation and worked perfect for the hello word. Then made a small Swing application with swing frame. I use eclipse RSE ( from your tutorial ) . Do i need to install something more on my BBB??
My final application is a arduino that will control the I/O’s of a 20 year old german AKEMAT CNC.
The BBB will communicate with the Arduino and serve as the user interface for through a TFT.
So you tutorials have all the cooking ingredient for me. I would however stcik to Java as i am most experienced in this language. A tutorial on USB communication on the BBB would be great !
thanks
Jan
I should have mentioned that my swing application didn’t work on my BBB.
Just a quick FYI the download page has moved to:
http://www.oracle.com/technetwork/java/embedded/downloads/javase/javaseembedded7u45archive-2098821.html
Thanks Derek . The tutorial is really helpful .
We need few clarifications . Is is possible to install tomcat on Beaglebone-black ?. Since Beaglebone comes with around 512MB of RAM , will it impact performance ? For tomcat , do we need to install tomcat for embedded use ?
Please clarify
Hi Derek, Do you know how can I install a java application to run on beaglebone at startup ? I’ve installed java headful because is a swing application. I want to launch everytime angstrom starts automatically.
Thanks in advance.
Hi Omar, you have to create a service — see /lib/systemd/system for examples e.g., mystartup.service. Test it using systemctl enable mystartup.service and when you sure it is working correctly uses systemctl start mystartup.service Kind regards, Derek.
Thanks Derek for your response. I’ve already tried this way with no luck:
~cd /usr/bin
~ln -s /usr/java/ejre1.7.0_75/bin/java
~cd /usr/java/ejre1.7.0_75/bin
~ls
PlainWindow.class java myapp.sh
~nano myapp.sh
#!/bin/sh –
exec java PlainWindow
~chmod +x myapp.sh
~chmod +x java
~cd /lib/systemd/system
~nano plain.service
[Unit]
Description=Init MyApp
[Service]
ExecStart = /usr/java/ejre1.7.0_75/bin/myapp.sh
[Install]
WantedBy=multi-user.target
~systemctl enable plain.service
~systemctl start plain.service
~systemctl status plain.service
plain.service – Init MyApp
Loaded: loaded (/lib/systemd/system/plain.service; enabled)
Active: failed (Result: exit-code) since Sat 2000-01-01 00:03:39 UTC; 5s ago
Process: 597 ExecStart=/usr/java/ejre1.7.0_75/bin/myapp.sh (code=exited, status=1/FAILURE)
CGroup: name=systemd:/system/plain.service
Hello Dr. Molloy,
Being very pleased for learning a lot using your BBB book and online tutorials I wish to you very much for this excellent work. Unfortunately there is a problem when installing JRE onto my BBB. It always ends in the same error shown below. Could you please let me know what I’m doing wrong? Thank you.
root@beaglebone:/usr/java# uname -a
Linux beaglebone 3.8.13-bone70 #1 SMP Fri Jan 23 02:15:42 UTC 2015 armv7l GNU/Linux
root@beaglebone:/usr/java# tar xzf ejre-7u75-fcs-b13-linux-arm-vfp-sflt-client_headless-18_dec_2014.tar.gz
root@beaglebone:/usr/java# ls
ejre-7u75-fcs-b13-linux-arm-vfp-sflt-client_headless-18_dec_2014.tar.gz
ejre1.7.0_75
root@beaglebone:/usr/java# export PATH=$PATH:/usr/java/ejre1.7.0_75/bin/
root@beaglebone:/usr/java# export JAVA_HOME=/usr/java/ejre1.7.0_75/
root@beaglebone:/usr/java# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/ejre1.7.0_75/bin/
root@beaglebone:/usr/java# echo $JAVA_HOME
/usr/java/ejre1.7.0_75/
root@beaglebone:/usr/java# java -version
-bash: /usr/java/ejre1.7.0_75/bin/java: No such file or directory
root@beaglebone:/usr/java#
Hi Jean, check that the java executable is in the /usr/java/ejre1.7.0_75/bin/ directory. You should be able to type ./java -version in that directory. If it is not there, try to find the java executable. Just for your information, I have added a guide to installing Java8 on the BeagleBone to: http://exploringbeaglebone.com/chapter5/ Hope that helps, Derek.
Script to install
https://gist.github.com/ricardojlrufino/1f9b15f84491a0131274
This script unpacks and sets up the environment variables and install the appropriate folder
Hello, Dr. Molloy, today i tried to install java using this tutorial, but for some reason, after i unzip the files and changed the variables but it says that the file doesn’t exist. i triple-checked the path and nothing! I was hoping you could help out
Kevin, it says that the command ‘java’ doesn’t exist, right? I bet you downloaded the Java Developers Kit (JDK). Oracle no longer provides and embedded JRE. You have to build your own. I have not yet had any luck building the JRE, but I’ll keep trying. In the meantime if anyone else has had luck, please let us know.
I have tried to install the latest, but an older one that indicated arm linux jdk-8u144-linux-arm64-vfp-hflt.tar
I extracted it and set the correct path and JAVA_HOME variables.
When I run the java -version command I get the following error:
cannot execute binary file: Exec format error
It’s almost like it is not compiled for ARM?
Any ideas?
By the way, the education series is excellent.