简体   繁体   中英

I’m having issues exporting runnable JAR using Java 1.9

I'm using Java 1.9 and Eclipse Oxygen and when I try to export Runnable JAR File it says JAR Creation error. When I see details it tells me that “Could not find main method from given launch configuration”. I've already selected the class file which has main method but same problem exists. If I try to do the same thing in Java 1.8 with Eclipse Oxygen it exports fine but with some warnings but that is ok. In Java 1.8 it exports. But in Java 1.9 with Eclipse Oxygen it does not export at all. Does anybody have this problem using Java 1.9 and Eclipse Oxygen? Please let me know the solution. Thanks in advance.

I have faced that issue before.

Solution 1:

right click in the class that have the main method

go to Run As and select Run Configurations...

make sure that property Main class is the right package path to the class that have main method

if the main method was in another class, delete its run config from the list at the left, So the app don't get confused.

在此处输入图片说明


Solution 2:

If the first one not working with you, So you can do the following:

after exporting the Jar file with error you mentioned

go to jar file and open it with extract tool ex. Winrar

enter to META-INF directory and view or edit the file MAINFEST.MF inside

add this line to the file with the right path:

Rsrc-Main-Class: right.path.to.class.ClassName

Save and try to run again..


Update according to comments

I have recheck it again, your problem is at export the Jar file, the selected launch configuration is wrong, because the path to main method is wrong.

Usually, this is happen because you change the class or class name that contain main method.

the best way to solve it is

1- remove all Java Application run config, that appear in the previous Pic.

2- re-run the app by clicking right mouse click on the project and select Run As and then select Java Application

3- After the app run successfully, try now to export the app you will find only one Lunch Configuration and it will be the right one.

also:

“Could not find main method from given launch configuration”

IF that is the export problem, a JAR file will appear but with no Main method path, So you can't run it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM