10

I developed my program using Eclipse as my IDE. I used to use File|Export| Runnable JAR file option for creating dist build for client.

I was working with project using Run or (often) Debug button in eclipse (so I have configuration for project with valid main method).

Unfortunately when I created build yesterday I had following error when I tried to run app:

Failed to load Main-Class manifest attribute from My.jar

Then when I retried exporting I found the following problem in export log:

Could not find main method from given launch configuration

I have no idea what could cause this problem. I think I hadn't change anything in my project configuration. And I'm test my builds so I'm sure this option used to work correctly.

I will appreciate any help.

Maciek Sawicki
  • 6,717
  • 9
  • 34
  • 48
  • Sometimes you may need to restart your DIE if you use one. [See this][1] [1]: http://stackoverflow.com/questions/13527869/could-not-find-main-method-from-given-launch-configuration-when-using-javasca – ABData Feb 12 '15 at 10:17
  • Sometimes you may need to restart your IDE if you use one. [See this][1] [1]: http://stackoverflow.com/questions/13527869/could-not-find-main-method-from-given-launch-configuration-when-using-javasca – ABData Feb 12 '15 at 10:20
  • You may need to restart your IDE if you use one. See this: http://stackoverflow.com/questions/13527869/could-not-find-main-method-from-given-launch-configuration-when-using-javasca – ABData Feb 12 '15 at 10:21

4 Answers4

6

Are you selecting correct 'Launch Configuration' in the export dialog? Make sure it's from your project.

Also, once exported you could unzip jar file and look into 'META-INF/MANIFEST.MF' file - there should be 'Main-Class' entry with fully qualified name of your class where the main() method is.

maximdim
  • 8,041
  • 3
  • 33
  • 48
  • Thanks for answerer. Yes I dubele checked that I selected valid Launch Configuration during export. One more thing can I just edit this file and crate new zip (jar)? Won't it change jar checksum or something (sorry for noobish question)? – Maciek Sawicki Nov 07 '10 at 10:35
  • I found answer for repacking question: "They can also use zip tools to do so; however, caution should be exercised as to the order of entries in the zip file headers as the manifest likely needs to be first." http://en.wikipedia.org/wiki/JAR_(file_format) – Maciek Sawicki Nov 07 '10 at 10:41
  • I accepting your answer because of two reasons:1. you help me to solve my problem (I used jar tool instead of zip). 2. after googling a little I think it's possible that better answer then "it eclipse bug" not exist. – Maciek Sawicki Nov 07 '10 at 19:17
2

I had this problem and none of the other options worked. Even removing and starting with a new workspace. In my case the problem was that I hadn't manually added the "classes" directory of my project to the classpath of the debug configuration that I was using to debug the java app. I don't know why it didn't pick up the classes directory automatically as part of the project from which I was running the app. In any case it started working again after that.

Waz
  • 21
  • 1
2

just had the same problem :s it's annoying but easy to manually fix in the manifest file.

  1. open the .jar file with winrar or 7zip.
  2. locate the manifest file (META-INF folder)
  3. change it to this.

Manifest-Version: 1.0 main-class: (package).(main-class)

In my case i had it in the default package.

Manifest-Version: 1.0 main-class: run

0

If you are not able to find your class file in Launch configuration, Right click on your project - > run as Java Application. Now export again.