Logan
Logan

Reputation: 2505

Unable to load main-class for jar file

I have developed an application using Eclipse IDE. After 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.

Upvotes: 2

Views: 3810

Answers (3)

VonC
VonC

Reputation: 1323175

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

alt text

Upvotes: 2

kgiannakakis
kgiannakakis

Reputation: 104168

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.

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114757

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.

Upvotes: 2

Related Questions