Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 669
Zybrion Avatar asked Nov 01 '16 00:11

Zybrion


1 Answers

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.

like image 103
Sir4ur0n Avatar answered Oct 12 '22 18:10

Sir4ur0n