Search code examples
eclipsejarexecutable-jarmanifest.mf

Could not find main method from given launch configuration


I've a simple Java project that works when I execute it at Eclipse environment. But when I try to export it to a Runnable Jar, I get the following error:

JAR export finished with warnings. See details for additional information.
Exported with compile warnings: JavaSwing/src.main.java/com/cansoft/GUIProgram.java
Exported with compile warnings: JavaSwing/src.main.java/com/util/Util.java
Jar export finished with problems. See details for additional information.
  Could not find main method from given launch configuration.

I read other posts which suggest to create a MANIFEST.MF file specifying the main-class which I did. It is placed at MyProjectFolder/META-INF/MANIFEST.MF and it contains the following information:

Manifest-Version: 1.0
Class-Path: resources
main-class: com.cansoft.GUIProgram

My main class is as follows:

public class GUIProgram {
    
    private JFrame folderCreationSubappFrame;
    private Color color;
    private String home;
    
    private final static Logger LOG_MONITOR = Logger.getLogger("com.cansoft");

    public static void main(String[] args) {
        try {
            new GUIProgram();
        } catch (Exception e) {
            LOG_MONITOR.log(Level.INFO,e.getMessage());
        }
    }

    public GUIProgram() throws InterruptedException, SecurityException, IOException {
        home = System.getProperty("user.home") + File.separator + "Documents";
        startLogSystem();
        if(isFirstRun()) {
            showWelcomeFrame();
        } else {
            initialize();
        }
    }  .... More and more code

Does anybody know what am I missing? Any help much appreciated.

Thank you.


Solution

  • I finally find out where the problem was, it was quite simple btw. I had created my GUIProgram within a src.main.java package, but that package was created (my bad) as resources instead of folders, so Eclipse was smart enought to run it but when trying to generate the JAR which expected a correct java project structure, it was failing because truly there were not GUIProgram java class at src path (src was not folder type but resources).

    Hope I succeed explaining.