4

I have programs that I need to run on the Raspberry Pi and show the output on an lcd connected to the Raspberry Pi.

I have used Java for the programming and JavaFX specifically for the GUI. But on running the program on the Pi, it gives different errors, sometimes not detecting javafx extensions, sometimes not being able to find the main classes.

The OS I'm using for Pi is Raspbian. And performing all the communication on Putty. I have tried using jdk 1.8.0, 1.7.0; ejdk; openjdk. But all seem to give different errors.

It would be really helpful if someone could tell me a way to install the relevant jdk and jre on the Pi, if I format my SD Card and start over with everything.

Also, programs without the use of Javafx run without a glitch on the Pi.

Karan Asthana
  • 326
  • 3
  • 13

1 Answers1

4

As you can read here, the most recent JDK versions for ARM don't include JavaFX.

If you want to use JavaFX in your Raspberry Pi, the solution is adding the missing JavaFX SDK.

If you install the recent Oracle's JDK for ARM from here (select jdk-8u111-linux-arm32-vfp-hflt.tar.gz), then you will need to download the JavaFX SDK from Gluon's site (select JavaFX Embedded SDK for armv6 hard float).

Once you have the file, unzip it, and copy the folders to your JDK.

Assuming you have downloaded armv6hf-sdk-8.60.8.zip to your Pi/Downloads folder, and you have unzip it to a folder armv6hf-sdk, like in the following picture:

Pi ARM JavaFX

using the following commands will allow you moving from command line the files to the JDK required folders. You can use a graphic tool for this as well.

cd Downloads
sudo chown -R root:root armv6hf-sdk
cd armv6hf-sdk
sudo mv lib/javafx-mx.jar /opt/jdk1.8.0_111/lib/
cd rt/lib/
sudo mv j* /opt/jdk1.8.0_111/jre/lib/
sudo mv arm/* /opt/jdk1.8.0_111/jre/lib/arm/
sudo mv ext/* /opt/jdk1.8.0_111/jre/lib/ext/ 

After that you should be able to run Java/JavaFX programs.

If you have a look also at the Gluon IDE plugins, you will be able to create projects on your desktop and deploy them remotely on your Pi (as well as on your desktop and mobile devices). Check the documentation here to set up your build script. And check the sample GluonSQLite here.

Community
  • 1
  • 1
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 1
    when i type the code sudo mv lib/javafx-mx.jar /opt/jdk1.8.0_101/lib/ it gives cannot stat "lib/javafx-mx.jar" no such file or directory as output. When i accesed the raspberry pi through winscp the javafx-mx.jar file was missing . when i tried to put javafx-mx.jar file with the help of winscp . it gives a dialogue box which says "permission denied Error code : 3" Please help me out with this problem. – Karan Asthana Nov 08 '16 at 18:08
  • 2
    Make sure you have downloaded the armv6hf-sdk.zip and then you have all the files extracted. Then use `chown`, and then copy or move the files to your local JDK installation folders as shown in the snippet above. Using winSCP you can verify that you have the files. – José Pereda Nov 08 '16 at 18:17
  • I've edited my answer with a picture of my local Pi/Downloads folder – José Pereda Nov 08 '16 at 18:40
  • Sir we did the same thing and gives the error that"cannot stat the Lib/javafx-mx.jar no such or file directory as output" – Karan Asthana Nov 08 '16 at 18:53
  • I can't say why you get that error. Are you able to see the files listed in your `Pi/Downloads/armv6hf-sdk` folder? If not, find out why. If you have them, first run the `chown` command, and then move the files. If error persists, edit your question and post a picture so we can see. – José Pereda Nov 08 '16 at 19:01
  • When I try this I get `‘/opt/jdk1.8.0_65/lib/’: No such file or directory` (Java version on device is 1.8.0_65, which I got from running `java -version`). I already used `sudo apt-get install oracle-java8-jdk`, but the jdk isn't where I expect it to be and when I run `update-alternatives --display java`, I get `java - auto mode link currently points to /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java - priority 318`, which doesn't make sense to me. Where is the jdk? (It says jre) – Joël Abrahams Apr 01 '17 at 13:46
  • 2
    If you run `sudo apt-get install oracle-java8-jdk` the JDK will be installed in `/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/`. I usually download it and manually install it, so it goes to `/opt/jdk1.8.0_111`. But once you find your JDK folder, the procedure to install JavaFX SDK is the same. – José Pereda Apr 01 '17 at 13:59
  • Alright so I did all these steps (so everything from `armv6hf-sdk` is where it should be). Yet, when I try to run my app as such `java -jar MyApp.jar` It says `Error: Could not find or load main class runnable.MainApp`. (`java -cp MyApp.jar MainApp.class` and `java -cp MyApp.jar MainApp` don't work either). I'm not entirely sure if it's relevant to the question, but I don't know where else to look. – Joël Abrahams Apr 01 '17 at 14:31
  • I think that's indeed another question. If you run `java -cp MyApp.jar` + main class, you need the full main class name (`package.name.MainApp`). – José Pereda Apr 01 '17 at 14:40
  • Actually no, it is indeed related to the question. I have the exact same problem as the person that asked the qeustion; that Pi doesn't know how to handle a JavaFX application (can't find main class). If I add the libraries from within my IDE (IntelliJ), it does find the main class but then I get errors regarding `es2` and `sw`, so presumably this is a bad idea (and I shouldn't have to add it from within the IDE). I followed your steps exactly as stated (but used `/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java` instead). Do you have any idea where else it could go wrong? – Joël Abrahams Apr 02 '17 at 17:12
  • It's hard to say. I suggest you post a new question, with all your details: jdk version, list of folder and files, and also owner and permissions of those files, java version and alternatives,... Also, post the sample you try to run. – José Pereda Apr 02 '17 at 17:22