2

I have this project on Eclipse 3.7 (Indigo) and planning to build the *.jar. I am to build the project by File > Export > Java.Runnable JAR File > Named the filename of the jar file > Finish. An error always return to me when running the jar file.

Could not find the main class: [package nmame].[Class name of Main class (PSVM) is located].
Program will exit.

In addition, MySQL Connector 5.1 was included as Referenced Library for JDBC use.

How can I resolve and be able to build a jar file that is running as runned on Eclipse as Java Application?

Thanks in advance.

David B
  • 3,269
  • 12
  • 48
  • 80

1 Answers1

2

When you export the project try selecting the option :

Copy required libraries into a sub-folder next to the generated jar

Screenshot

This will create a lib folder containing the required dependency libraries ..

You have also to select a valid launch configuration for the program, to make sure that the MANIFEST file will be created with the MAin class attribute populated correctly .

When you run the generated jar you should run it with this command line (READ the MANIFEST.MF) :

java -jar yourjar.jar

or with Main class specified in the command line :

java yourjar.jar MainClass
aleroot
  • 71,077
  • 30
  • 176
  • 213
  • I still get the same error message. How could I set my Main class in the Manifest file? – David B May 09 '12 at 11:57
  • Yes, you can open the MANIFEST.MF and see whats inside, but are you running the jar with the -jar option ? – aleroot May 09 '12 at 11:58
  • Sorry, but where can I see the MANIFEST.MF in the project folder. I was just running the jar by double clicking the file. I was hoping building the jar file in Eclipse is easy as building one using Netbeans. – David B May 09 '12 at 12:03
  • The `java -jar yourjar.jar` did work. How can I make the jar file runnable itself by just double-clicking the file itself. Similar to the ones built by Netbeans. – David B May 09 '12 at 12:08
  • It depends on the file association of your operating system, take a look here : http://stackoverflow.com/questions/354664/executing-a-jar-on-vista-with-a-double-click – aleroot May 09 '12 at 12:16