0

I'm trying to learn JavaFX in combination with a Raspberry Pi with the OS Raspian (Jessie). Right now I'm coding in IntelliJ IDE with a basic example of JavaFX. My Windows 10 PC is using the newest SDK. 8.0 JDK. The Raspian is using 8.0

When I compile the software on my Windows PC I'm getting a .jar File. I made sure that the Artifacts are correct and linked to the main class of the package. The problem what I expecting is when I run the .jar on the Raspberry that I'm getting the following error:

Error: Could not find or load Main class sample.Main

The command that I'm executing:

java -jar care.jar

I made sure that the JDK is installed correctly. The Java package should be compiled right for Linux.

The code that I'm using is a standard example of IntelliJ. sample.Main

 package sample;

        import javafx.application.Application;
        import javafx.fxml.FXMLLoader;
        import javafx.scene.Parent;
        import javafx.scene.Scene;
        import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

sample.fxml

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>

Artifacts settings

Structure tree + IDE overview

I tried to add the .class files in the same directory of the .jar file. But with no luck.

1 Answers1

1

The error message says that your java -jar command tries to find a class named main in the sample package. But your class is named Main.

There probably is a wrong entry in your manifest file for the Main class attribute with main spelled with a lower case 'm' instead of Main with a capital 'M'.

Edit/Update:

The jar file is quite alright, I suppose it is a problem with the Java installation on the Raspberry Pi.

Here some links concerning that problem:

Can JavaFX be used on Raspberry Pi

How can i get JavaFX working on raspberry pi 3

https://www.experts-exchange.com/questions/29008944/Running-JavaFX-on-the-Raspberry-Pi.html

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
  • Thanks of Thinking with me :), i just checked the MANIFEST.MF and it seems to use sample.Main as main-class. So that must be fine... I didnt write it down with a capital on this website.. Sorry. – Jacco Veldscholten Nov 23 '17 at 20:53
  • can you do a `jar tvf care.jar` on the raspberry and check that you have a _Main.class_ file in the _sample_ directory? – P.J.Meisch Nov 23 '17 at 21:02
  • This is the output of that commend: https://image.prntscr.com/image/S-n4fL-8Rte3fQCaQOPonw.png I guess this is right.... – Jacco Veldscholten Nov 23 '17 at 21:14
  • that's strange. I was suspecting that there might be a file name problem with upper/lowercase names which make no problems on Windows but do on Linux. Another test: does `java -jar care.jar sample.Main` work - explicitly giving the class to run? – P.J.Meisch Nov 23 '17 at 21:25
  • 1
    which version of Java 8 does run on the raspberry? Does it have JavaFX? Please check this question;: https://stackoverflow.com/questions/36961054/can-javafx-be-used-on-raspberry-pi – P.J.Meisch Nov 23 '17 at 21:28
  • I tried the command, and the same results. https://image.prntscr.com/image/f6QFzXHHR_6bsvK2cc-lXA.png I already checked if the Raspberry is able to run javaFX. And it is! But if i'm missing library's then the system wil notify me. But right now it isn't even executing my software. – Jacco Veldscholten Nov 23 '17 at 21:47
  • sorry. `java -cp care.jar sample.Main`. -jar will read the manifest. – P.J.Meisch Nov 23 '17 at 21:55
  • No problem PJ, Am very happy that someone is willing to help me :). I still got the same message. This thing is insane.... https://image.prntscr.com/image/325-C6zeS_2a5ZM1RDNxNg.png – Jacco Veldscholten Nov 23 '17 at 22:01
  • but I'm running out of ideas. on the pi, please do a `jar xf care.jar`. This should extract the files of the jar in the current directory. Does a `java sample.Main` work then? Is there the _Main.class_ file in the _sample_ directory? – P.J.Meisch Nov 23 '17 at 22:04
  • Hmmm... Still same error, i packed out the Jar with the command. And this is the result of the sample directory: https://image.prntscr.com/image/-9K3GyDSR4Sm6G2egONJuA.png IT seems to be good, only one main.class. – Jacco Veldscholten Nov 23 '17 at 22:06
  • hm, no more ideas at the moment. getting late here. Do you have a possibility to place the jar somewhere where I can download it tomorrow? If it's only some sample code, that should be possible? – P.J.Meisch Nov 23 '17 at 22:19
  • Thanks for doing this :) Yes it is. http://jacco-veldscholten.nl/care.jar its just a basic JavaFX example from intellij. Its working fine on Windows. – Jacco Veldscholten Nov 23 '17 at 22:23
  • just checked the jar, that's all fine. Working here on a Mac with no problems. So it must be something with the JDK on the Pi. What does `java -version` give? – P.J.Meisch Nov 24 '17 at 06:18
  • Got the version. Its 1.8.0_65 https://image.prntscr.com/image/de7fJZNmQL2J8rzXCBz-ow.png Thanks for trying :) – Jacco Veldscholten Nov 24 '17 at 15:50
  • I updated my answer, I think this must be a problem with the Java installation on the Pi. Sorry that I can't help you further with that, I added some links to my answer that will hopefully help you. – P.J.Meisch Nov 24 '17 at 16:24