<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Java on the Raspberry Pi</title><link>https://community.element14.com/products/raspberry-pi/w/documents/11074/java-on-the-raspberry-pi</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>Java on the Raspberry Pi</title><link>https://community.element14.com/products/raspberry-pi/w/documents/11074/java-on-the-raspberry-pi</link><pubDate>Fri, 08 Oct 2021 05:29:34 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:346ead3a-bd8f-4201-832c-5ca90516544b</guid><dc:creator>PEarle</dc:creator><comments>https://community.element14.com/products/raspberry-pi/w/documents/11074/java-on-the-raspberry-pi#comments</comments><description>Current Revision posted to Documents by PEarle on 10/8/2021 5:29:34 AM&lt;br /&gt;
&lt;p style="margin:0;"&gt;Java is now available for the Raspberry Pi through the Pi4J Project - more details &lt;a class="jive-link-external-small" href="http://pi4j.com/" rel="nofollow ugc noopener" target="_blank"&gt;here.&lt;/a&gt; As a Java developer myself, I decided to see how easy/difficult it would be to install Java on my Pi - so here&amp;#39;s how I went about it. All the information below is available from Pi4J, but I thought it would be helpful to document the steps I went through.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;Operating System&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;First off, you must use the &lt;span style="color:#262626;font-family:Arial, Helvetica, Geneva, sans-serif;"&gt;&lt;strong&gt;Debian &lt;/strong&gt;&amp;quot;Wheezy&amp;quot; &lt;/span&gt;operating system on your Pi - pi4J wont work with Raspbian (which is what I had installed when I started). The reason for this is apparently: &lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;It turns out that this is an issue related to hard float versus soft float. The Pi4J native library was compiled against the Debian &amp;quot;Wheezy&amp;quot; soft-float image and users attempting to run it on the Raspbian &amp;quot;Wheezy&amp;quot; hard-float image are encountering this issue.&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;If you haven&amp;#39;t got Debian Wheezy installed, you need to get that before you go any further - you can get it from &lt;a class="jive-link-external-small" href="http://www.raspberrypi.org/downloads" rel="nofollow ugc noopener" target="_blank"&gt;http://www.raspberrypi.org/downloads&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;. If you aren&amp;#39;t to sure about installing there&amp;#39;s a helpful page available at &lt;a class="jive-link-external-small" href="http://elinux.org/RPi_Easy_SD_Card_Setup" rel="nofollow ugc noopener" target="_blank"&gt;http://elinux.org/RPi_Easy_SD_Card_Setup&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;. &lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;JDK Install&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;Once you have got this installed you can start on the jdk installation. What I did was to download this to my PC and then copy it to my Pi using WinSCP (available from &lt;a class="jive-link-external-small" href="http://winscp.net/eng/index.php" rel="nofollow ugc noopener" target="_blank"&gt;http://winscp.net/eng/index.php)&lt;/a&gt;&lt;/span&gt;. Get the JDK from&amp;nbsp; &lt;a class="jive-link-external-small" href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" rel="nofollow ugc noopener" target="_blank"&gt;http://www.oracle.com/technetwork/java/javase/downloads/index.html&lt;/a&gt;. You need to click on the &lt;em&gt;&lt;strong&gt;JDK DOWNLOAD &lt;/strong&gt;&lt;/em&gt;button (as shown below) and then find the &lt;strong&gt;jdk-7u10-linux-arm-sfp,tar.gz&lt;/strong&gt; distribution, and download it to your Pc.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/300x300/__key/communityserver-wikis-components-files/00-00-00-01-69/contentimage_5F00_26291.png"&gt;&lt;img alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/69/contentimage_26291.png-300x300.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=vdZ%2BaWDzwZQZYIcvJS3zUOnTMcpUWyMNI%2BraRfV6J1U%3D&amp;amp;se=2026-04-22T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=zKY9Cgj81Y+etN0Sz0NFxQ==" style="max-height: 300px;max-width: 300px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/620x300/__key/communityserver-wikis-components-files/00-00-00-01-69/contentimage_5F00_26292.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/69/contentimage_26292.png-620x300.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=%2B7Q8N5jeZ1ZGWmc5OzkmYjNRSQiBtyEO3SPd70sbKL0%3D&amp;amp;se=2026-04-22T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=1qvH5s+p4DsLO9CmUDN7qQ==" style="max-height: 300px;max-width: 620px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Once the tar file in on your PC, copy it to the Pi (e.g. using winSCP). I put it in the pi user home directory (/home/pi) - and the following instructions assume it is there.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Open up a command prompt on your Pi, and then go through the following steps.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Untar the jdk distribution (i.e. the tar file copied above)&lt;/li&gt;&lt;/ul&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;tar xvzf ~/jdk-7u10-linux-arm-sfp.gz&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create a java directory and move the untarred distribution to it. delete the tar file once we are done (don&amp;#39;t need it any more)&lt;/li&gt;&lt;/ul&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;sudo mkdir -p -v /opt/java&lt;br /&gt;sudo mv -v ~/jdk1.7.0_10 /opt/java/&lt;br /&gt;rm ~/jdk-7u10-linux-arm-sfp.gz&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:10pt;"&gt;Create paths to the java and javac commands (so that they can be used) anywhere. When you have done this try the java --version command - if everything is done correctly this will return some information about the java installation&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;sudo update-alternatives --install &amp;quot;/usr/bin/java&amp;quot; &amp;quot;java&amp;quot; &amp;quot;/opt/java/jdk1.7.0_10/bin/java&amp;quot; 1&lt;br /&gt;sudo update-alternatives --set java /opt/java/jdk1.7.0_10/bin/java&lt;br /&gt;sudo update-alternatives --install &amp;quot;/usr/bin/javac&amp;quot; &amp;quot;javac&amp;quot; &amp;quot;/opt/java/jdk1.7.0_10/bin/javac&amp;quot; 1&lt;br /&gt;sudo update-alternatives --set javac /opt/java/jdk1.7.0_10/bin/javac&lt;br /&gt;&lt;br /&gt;java -version&lt;/pre&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;margin-bottom:1em;color:#262626;font-family:Arial, Helvetica, Geneva, sans-serif;"&gt;Java is now installed!!&amp;nbsp; there are a few further steps required to set up the environment variables, so do the following ;&lt;/p&gt;&lt;p style="margin:0;margin-bottom:1em;color:#262626;font-family:Arial, Helvetica, Geneva, sans-serif;"&gt;Some Java programs require a JAVA_HOME environment variable to be configured on the system.&amp;nbsp; Add the following line to you &amp;quot;/etc/environment&amp;quot; using your favourite text editor.&lt;/p&gt;&lt;pre style="color:#262626;"&gt;JAVA_HOME=&amp;quot;/opt/java/jdk1.7.0_06&amp;quot;&lt;/pre&gt;&lt;p style="margin:0;margin-bottom:1em;color:#262626;font-family:Arial, Helvetica, Geneva, sans-serif;"&gt;&lt;br /&gt;Also, edit your &amp;quot;~/.bashrc&amp;quot; file using this command&lt;/p&gt;&lt;pre style="color:#262626;"&gt;nano ~/.bashrc&lt;/pre&gt;&lt;p style="margin:0;margin-bottom:1em;color:#262626;font-family:Arial, Helvetica, Geneva, sans-serif;"&gt;and add the following two lines to the bottom of the file and save.&lt;/p&gt;&lt;pre style="color:#262626;"&gt;export JAVA_HOME=&amp;quot;/opt/java/jdk1.7.0_06&amp;quot;&lt;br /&gt;export PATH=$PATH:$JAVA_HOME/bin &lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;"&gt;&lt;strong&gt;Installing Pi4J&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Pi4J is installed quite simply on the Pi by using the following commands which will download and install the distribution;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;wget http://pi4j.googlecode.com/files/pi4j-0.0.5.deb&lt;br /&gt;sudo dpkg -i pi4j-0.0.5.deb&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Pi4J is now installed in /opt/pi4j. This comes with some example classes and a build script which you can now run. this will also test that your java install is set up correctly. Navigate to the examples root and run the build as follows&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;cd /opt/pi4j/examples/&lt;br /&gt;./build&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;You can now test the examples. I have a PiFace connected to my Pi, and there are a couple of test classes on mine so I ran the following command to run one of them. Note the class declaration which you must use in the java command in order to pick up the P14J libraries. You also have to be in the correct location to pick up the class - i.e. &lt;em&gt;&lt;strong&gt;/opt/pi4j/examples&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;cd /opt/pi4j/&lt;span style="font-size:10pt;"&gt;examples/&lt;/span&gt;&lt;br /&gt;sudo java -classpath .:classes:/opt/pi4j/lib/&amp;#39;*&amp;#39; PiFaceGpioExample&lt;/pre&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;And that&amp;#39;s it - Java installed and classes running in a few simple steps!&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:10pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;There&amp;#39;s more information available at the &amp;#39;official&amp;#39; oracle link &lt;a class="jive-link-external-small" href="http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html" rel="nofollow ugc noopener" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;background-color:#fbfbfb;font-family:Helvetica, arial, freesans, clean, sans-serif;"&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;Debian Wheezy - &lt;/span&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt; &lt;/span&gt;&lt;a class="jive-link-external-small" href="http://www.raspberrypi.org/downloads" rel="nofollow ugc noopener" style="font-family:Helvetica, arial, freesans, clean, sans-serif;" target="_blank"&gt;http://www.raspberrypi.org/downloads&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;WinSCP - &lt;a class="jive-link-external-small" href="http://winscp.net/eng/index.php" rel="nofollow ugc noopener" target="_blank"&gt;http://winscp.net/eng/index.php&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;JDK - &lt;a class="jive-link-external-small" href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" rel="nofollow ugc noopener" target="_blank"&gt;http://www.oracle.com/technetwork/java/javase/downloads/index.html&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;Pi4J - wget http://pi4j.googlecode.com/files/pi4j-0.0.5.deb&lt;/span&gt;&amp;nbsp; (followed by &lt;em&gt;sudo dpkg -i pi4j-0.0.5.deb)&lt;/em&gt;&lt;/li&gt;&lt;li&gt;Orace JDK - &lt;a class="jive-link-external-small" href="http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html" rel="nofollow ugc noopener" target="_blank"&gt;http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html&lt;/a&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-family:Helvetica, arial, freesans, clean, sans-serif;background-color:#fbfbfb;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: pi4j, pi, java_programming, piface&lt;/div&gt;
</description></item></channel></rss>