0

Before you mark this as a duplicate, I'd like to say that I've visited probably every thread made on the subject and still can't find a solution. I tried reinstalling JRE, configuring my classpath, etc. I've tried every solution I found but it still doesn't work. I can launch the program just fine using my IDE but it won't launch when trying to execute the jar file. I tried launching it with a .bat file and via command prompt. Here is my Manifest file:

Manifest-Version: 1.0
Class-Path: C:\Users\Badr\IdeaProjects\JavaGame1\src\com\rsp\game\Game.java
Main-Class: com.rsp.game.Game

And yes, I do have the main method included in my Game class. I've heard that the main class shouldn't be included in a package but I don't know if that's true or not.

9
  • How are you trying to execute? It sounds like you're creating a jar and try to run that? Like in java -jar yourjarfile.jar ? Apr 23, 2016 at 19:30
  • @VolkerKueffel Yes, that's exactly what I'm doing.
    – Badr B
    Apr 23, 2016 at 20:13
  • And when you run jar -ft yourjarfile.jar it shows com/rsp/game/Game.class? Apr 24, 2016 at 1:01
  • 1
    Well, there you go. If you don't package your classes into the jar you can't run them from there. You can still run your code if you cd into JavaGame1 and execute java -cp . com.rsp.game.Game. If you want to run if from the jar you obviously have to build your jar correctly first. Apr 24, 2016 at 3:26
  • 1
    @VolkerKueffel THANK YOU. I solved it by removing the Class-Path like you said. Thank you very much.
    – Badr B
    Apr 26, 2016 at 2:52

1 Answer 1

1

Your Class-Path is incorrect; it needs to be set to the folder that contains com (because the directory structure is part of the fully qualified class name), and you need to compile your .java source files to class files.

I've heard that the main class shouldn't be included in a package but I don't know if that's true or not.

That is not true, but the main class name must be fully qualified (and Main-Class: com.rsp.game.Game is).

3
  • I found a directory in my project that stores the .class files, however it still gives me the same error with the following classpath: C:\Users\Badr\IdeaProjects\JavaGame1\out\production\JavaGame1
    – Badr B
    Apr 23, 2016 at 19:02
  • The directory that stores com, which stores rsp, which stores game, which stores Game.class; you need to point to the parent folder of com. Apr 23, 2016 at 19:02
  • Yeah JavaGame1 contains com which contains rsp which contains game which contains Game.class.
    – Badr B
    Apr 23, 2016 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.