Search code examples
javaraspbianraspberry-pi2

Error: Could not find or load main class: running compiled JAR different errors depending on how I run it


PREFACE! I know similar questions have been asked a million times. I have read MANY hundreds of the previous questions and still cannot find my answer.

I am working on a raspberry pi and trying to run a Java application that is packaged in a Jar file. It was working fine before I installed the latest Java 1.8_111. I downgraded and it still didn't work. I then wiped my pi to defaults and it is still not working.

The current Java version is 1.8.0_65. I have decided that the java version is irrelevant by installing multiple different versions with the same result. When I installed a different version no other version was present to cause conflicts.

If I run the jar by simply doing java -jar KitchenScr.jar I get the following error:

Error: Could not find or load main class com.javafx.main.Main

If I run the jar from the supplied shell script(below). I get the following error.

Script

#!/bin/sh

DIRNAME=`dirname $0`
CP=$DIRNAME/KitchenScr.jar

# start uniCenta oPOS
java -cp $CP uk.chromis.kitchenscr.KitchenScr 

Error

Error: Could not find or load main class uk.chromis.kitchenscr.KitchenScr

If I left anything out please let me know.


Solution

  • This was a simple issue that was staring me in the face.

    Error: Could not find or load main class com.javafx.main.Main

    Oracle stopped releasing JavaFX for ARM around Update 30 or something. It worked initially when I first bought my pi, but not after I installed a new OS because a newer version of Java was running.

    Downgrade Java or add relevent ARM libraries for JavaFX.