6

I tried troubleshooting this problem for about 4 hours. Nothing worked. I am using Java and Intellij and JavaFX.

What do I want to do? I have created a JavaFX programm on Windows. I want to execute this .jar on my Raspberry Pi.

Whenever I want to execute this jar I get this error in the console:

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

sample is the package and Main is my class with the main method.

The programm works JUST FINE under windows. (In and outside of IntelliJ).

What steps did I already do?

  1. Java is up-to-date on my pi. java -version returns 1.8. So we are good here.

  2. I have imported my used libraries (Pi4J) in my project under project-structure -> libraries. & under modules -> dependencies.

  3. I have defined a new artifact. I set a main Class (sample.Main) & under JavaFX I set the application class to sample.Main (both are given to me by Intellij) I then build the project by going to build -> build artifacts.

  4. I checked the MANI-FEST under /src/META-INF/MANI-FEST and it indeed has Main-Class: sample.Main

  5. On my pi I went to the direction in which the jar file is. Then I ran: sudo java -jar Keimgeraet.jar which should work just fine. But then I get the error.

  6. I probably have done more but forgot it already...

What might work but I don't know how I would to that:

In other threads people mentioned that my specified paths could be wrong on another computer (in this case the pi)

Here are some pictures [imgur] how everything is set up. Maybe that helps.

I will gladly try any answer! I am not the most experienced with java and the pi but I am not a complete starter.

Sidequestion: How can I include all the libraries in one final jar file?

If you need any more details feel free to ask!

Nissa
  • 4,636
  • 8
  • 29
  • 37
Zybrion
  • 141
  • 7
  • 1
    Regarding your last question, what you want is called a fat jar, and you probably could convert your project to use Maven to build your project into one – OneCricketeer Nov 01 '16 at 00:33
  • Thank you. I will look into that once I figure out how to make this jar work on the pi :-( – Zybrion Nov 01 '16 at 01:01
  • 1
    Good, well researched question. You've made an excellent first impression :) – Nissa Nov 01 '16 at 01:58
  • I get this error too ... when i build JavaFX programs with MAVEN seems really strange. – GOXR3PLUS Nov 01 '16 at 18:38
  • 1
    if you find a solution please let me know... after 10 hours of troubleshooting I don't know what else to do anymore – Zybrion Nov 01 '16 at 18:51

1 Answers1

2

How can I create an executable JAR with dependencies using Maven?

This should solve at once your main class declaration (in archive.manifest.mainclass in the maven plugin) and your inclusion of all libraries in the final jar (this will build two JARs: pay attention to take the one "xxx-jar-with-dependencies.jar").

If it still doesn't work with this Maven plugin, let us know.

Community
  • 1
  • 1
Sir4ur0n
  • 1,753
  • 1
  • 13
  • 24
  • Ok. so I have implemented the maven framework and followed [this answer](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven). I can now build 2 jar files and one of them is a jar with dependencies. This jar file works once again on my computer but doesn't on the pi. It is the same error. Maybe the build process from maven is interesting because it gives me a warning about platform dependency. I once again attached [pictures here](http://imgur.com/a/1btez). Maybe this will help. Thank you very much for your help btw. – Zybrion Nov 01 '16 at 11:27
  • The jar even works on my other windows machine. So it must be incompatible with linux (and its directory) or something... – Zybrion Nov 01 '16 at 11:34
  • 1
    Please see https://maven.apache.org/general.html#encoding-warning. Try to set your encoding to UTF-8 and test again. Also, once the jar compiled, try to open it (with 7zip or anything) and check it contains a manifest with the Main class properly configured. last test you can try is to create a Ubuntu VM and to run the jar (or maybe even build?) to see if it comes from the Raspberry Pi or not. – Sir4ur0n Nov 01 '16 at 19:41
  • I added the given properties in the pom file but when I compile with maven the warning still shows up. I have already opened the jar with 7zip but there is a META-INF folder with the manifest file. Inside the manifest file the main class (sample.Main) is defined. I have also tried copying my full Intellij folder and building on the pi with maven but then I get many errors. [Some of the errors](http://imgur.com/a/OxNjw) – Zybrion Nov 01 '16 at 20:10
  • One small update: I put the properties in the wrong project folder... The warning is now gone but the jar still does not run on the pi. – Zybrion Nov 01 '16 at 20:26
  • I just used another distribution and maven compiled with mvn package successfully! But when I wanted to execute the jar there was a weird error (not the one mentioned above) so I installed Java 8 from Oracle with [this guide](http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html). But after I installed Java I received the error: could not find or load main class again. So I tried mvn package again but now I get this really long error about the JavaFX files again (see link (some of the errors))... So I just don't know what to do anymore. – Zybrion Nov 01 '16 at 20:59