2

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.

Logan
  • 2,445
  • 4
  • 36
  • 56
  • Please post the command you use to 'run' the application (like: `java -jar myjar.jar`) as there are 'millions' of reasons why running a jar could fail. – Andreas Dolk Jun 14 '10 at 09:29

3 Answers3

2

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

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.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
0

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.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194