开发者

Unable to load main-class for jar file

开发者 https://www.devze.com 2023-01-03 04:13 出处:网络
I have developed an application using Eclipse IDE. Aft开发者_JAVA技巧er creating the application I exported the project in jar format. When I am trying to run this jar file, I get the error: Unable to

I have developed an application using Eclipse IDE. Aft开发者_JAVA技巧er creating the application I exported the project in jar format. When I am trying to run this jar file, I get the error: Unable to load main class. Please Help.


When you are exporting your project as a jar (see this SO question), you must specify your main class in the export Jar wizard.

Unable to load main-class for jar file


This should work always:

java -cp MyJar.jar pkg.name.MyClass

I'd prefer this anyway because it causes less classpath trouble compared to the java -jar way of starting a java application.


You need to create a runnable jar file. From Eclipse 3.4 you can do that by choosing Export, Java, Runnable Jar File. If you also want to include dependencies have a look at the Fat Jar plug-in.

0

精彩评论

暂无评论...
验证码 换一张
取 消