0

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.

Charles
  • 282
  • 1
  • 4
  • 18

2 Answers2

1

It is not enough to create the manifest file, you need to explicitly choose it in the Eclipse jar export dialog.

Answer to Comment

If you use "runnable jar", make sure that you chose the correct launch configuration and that the launch configuration successfully runs when chosing "Run As" -> "Run Configurations" -> "Java Application" -> Your Configuration -> "Run"

Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118
  • Hello Konrad and thank you for your answer, but Manifest selection option only appears when exporting Jar, not runnable JAR (If I export it as JAR, I have two options: let wizard to create Manifest or choose mine from a path). – Charles May 12 '22 at 11:57
  • Hi Konrad. Yes, If I launch the run configuration, the app starts and operates normally. Please, take a look to the run configuration: https://ibb.co/71G90DD and to the Export dialog: https://ibb.co/k9ZkL3f. Thanks again – Charles May 12 '22 at 12:25
0

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.

Charles
  • 282
  • 1
  • 4
  • 18