0

i'm working in my tablet a project that i want to run in my raspberry pi. The IDE AIDE, that i'm using can't export my project as an executable jar file. so i decided to try that by using the command line I used:

jar cvf ServerActivities.jar *

too create the jar file whichbworked but when i want to start it by using

Java -jar ServerActivities.jar

it says that my Main class couldnt be found or loaded, but it exists and contains an main method

Calits95
  • 21
  • 4
  • 2
    Is it a `Main-Class`entry in your MANIFEST? – Albert Nov 02 '15 at 13:10
  • 1
    You need to specify which class contains the main method that you want to run. Why: Imagine all of your classes have a main method. Then the virtual machine doesn't know which one to pick. So you have to put that information into the jar file. – f1sh Nov 02 '15 at 13:15
  • You need to specify where is your manifest when you create your jar. For instance: `jar cvmf ServerActivities.jar META-INF/MANIFEST.MF *` – Albert Nov 02 '15 at 13:38

1 Answers1

2

You need to create a manifest and point to your Main class from there.

See: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html or: How to setup Main class in manifest file in jar produced by NetBeans project

Community
  • 1
  • 1
Rens Groenveld
  • 960
  • 11
  • 28
  • i mean the steps of the first link ^^ – Calits95 Nov 02 '15 at 13:25
  • Not sure why, maybe you did something wrong. Another way of running the jar is to run it with the -cp command from the command prompt. You can then specify the main class it should run. In your case, it will look something like this: java -cp ServerActivities.jar com.path.to.main.class.MainClass. You then don't need a manifest file. – Rens Groenveld Nov 02 '15 at 13:47
  • Do i need the path thats created inside the jar file to specify the Main Class or just the package in that i put the Main Class? Because with using Java -CP ServerActivities.jar mypackage.MainClass i still get the error :/ – Calits95 Nov 02 '15 at 13:57
  • And it worked all fine when creating the jar by eclipse so i have no clue why it doesnt work now :( – Calits95 Nov 02 '15 at 13:57
  • Try opening the created jar with a program like 7zip. You can browse through the jar file and see if your compiled classes are actually in the jar file. – Rens Groenveld Nov 02 '15 at 14:15
  • By the way, mypackage.MainClass seems fine. I suspect something went wrong while creating the jar. – Rens Groenveld Nov 02 '15 at 14:17
  • My class is there, i also looked in the created Manifest.MF and there was no path to the Main class, can that be the fault? – Calits95 Nov 02 '15 at 14:28
  • In case of using "Java -jar ServerActivities.jar" you definetely need it. 7zip allows you to alter the manifest within the jar. You can try to manually add the 'Main-Class: MyPackage.MyClass' in your manifest and save it. Then re-run the "Java -jar ServerActivities.jar" and see if it helped. For an example of the manifest file, see: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html – Rens Groenveld Nov 02 '15 at 14:49
  • Created a new jar file now, and now there is the path of my Main class in the Manifest.mf, but now i have MainClass.Java instead of MainClass.Class in my package :/ – Calits95 Nov 02 '15 at 16:12
  • You don't seem very lucky. Have you tried to edit the empty manifest by hand on the Jar with the correctly compiled classes? – Rens Groenveld Nov 02 '15 at 22:42
  • No, i was a genius and overwrote it .___. – Calits95 Nov 03 '15 at 12:56
  • Being a genius is awesome. Sorry, it is hard to help without knowing exactly what you did or what you didn't do. I suggest you try again from the beginning following the steps in the links provided earlier. If it comes to the point again that you have an empty manifest, try to edit it manually. – Rens Groenveld Nov 03 '15 at 13:12
  • I followed the steps from the beginning, but i keep getting a filled Manifest and Java files instead of Classes :( – Calits95 Nov 03 '15 at 13:14
  • When i have a working jar, could i copy my updated classes then in the jar with 7zip and it would still work? – Calits95 Nov 03 '15 at 16:22