无法从给定的启动配置中找到主要方法

Could not find main method from given launch configuration

我有一个简单的 Java 项目,当我在 Eclipse 环境中执行它时它可以工作。但是,当我尝试将其导出到 Runnable Jar 时,出现以下错误:

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.

我阅读了其他帖子,建议创建一个 MANIFEST.MF 文件,指定我所做的 main-class。它位于 MyProjectFolder/META-INF/MANIFEST.MF,包含以下信息:

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

我的主要class如下:

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

有人知道我错过了什么吗?非常感谢任何帮助。

谢谢。

仅创建清单文件是不够的,您需要在 Eclipse jar 导出对话框中明确选择它。

回复评论

如果您使用“可运行的 jar”,请确保您选择了正确的启动配置,并且在选择“运行 As”->“运行 Configurations”时启动配置成功运行 - > "Java 应用程序" -> 你的配置 -> "运行"

终于找到问题出在哪里了,很简单。我在 src.main.java 包中创建了我的 GUIProgram,但该包是作为 resources 而不是文件夹创建的(我的错),所以 Eclipse 足够聪明 运行它但是当试图生成期望正确的 java 项目结构的 JAR 时,它失败了,因为确实没有 GUIProgram java class 在 src 路径(src 不是文件夹类型但资源)。

希望我解释成功。