Reputation: 105
i'm trying to export my Java Project into a runnable JAR file with eclipse but if i want to run the finished JAR file I always get the error
Java Virtual Machine Launcher
Could not find the main class: src.main. Program will exit.
src.main
is my main class, if i open the jar with winrar this class is in the folder src in the jar file.
I export the Project like this:
The libraries are added like this:
What am I doing wrong?
Upvotes: 0
Views: 4567
Reputation: 547
The first thing that I recommend you: don't use src.main in the way that you are doing it right now. In Java usually we use a folder called src or src/main or src/main/java to put the sources. Then, to use this as a package and class name is not a good idea. Secondly; don't call your class main it is not a keyword in Java, you can create a class with this name but... it's not a good idea.
And the solution to your problem: you need to set up your Main-Class and your Class-Path in your manifest file and be sure about the structure of your package (your jar), take a look into this tutorial, it will help you.
Upvotes: 0
Reputation: 1716
Does src.Start have a proper "public static void main(String[] args)" method?
Are you trying to start the app like this:
"java -jar myjar.jar" or "java -cp myjar.jar src.start"
Also, are you building the manifest by hand, or letting eclipse do it? I don't remember ever seeing eclipse add a classpath entry in the manifest but I might have missed it.
On the "Jar Manifest Specification" panel during the export, just select "generate the manifest file" and fill in the "Main class:" entry in the input field.
Upvotes: 1