Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raspberry Pi and Java Installation

I am attempting to install Oracle's Java jdk and compile and run java programs on my Raspberry pi. Basically I am getting a Error: Could not find or load main class error when I try to run a java myfile.java.

The steps I took were:

  1. Downloaded "wheezy" from the Raspberry Pi website that allows java (soft float)
  2. Downloaded the arm jdk from Oracle's website
  3. Used the command tar -zxvf jdk-7u6-linux-arm-sfp.gz to unzip the jdk
  4. Wrote, compiled, and then attempted to run a simple java program

On a side note, because the wheezy image was only 2GB, I partitioned the other 2GB of my 4GB SD card for some additional storage. That is where I unzipped my jdk and now when I want to run java or javac I have to use the full path. How can you modify the installation so that you can simply type in java with out the full path. Doesn't that have something to do with where the binaries are installed?

like image 875
Matthew Avatar asked Apr 09 '26 13:04

Matthew


1 Answers

The JRE sounds like it's installed ok but you need to compile your java before you can run it. As the Pi is relatively slow, use your PC/Mac to compile your app:

javac myfile.java

Then you can copy myfile.class, which should contain a main method, to your Pi and run:

java your.package.name.myfile

You can test this on your PC/Mac (or Linux :) ) before copying to your Pi.

Your other issue is resolved by adding java to the PATH. Edit /etc/profile, and add:

PATH=${PATH}:/path/to/jdk/bin
like image 182
Alastair McCormack Avatar answered Apr 12 '26 03:04

Alastair McCormack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!