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

发布于 2025-01-28 02:47:58 字数 1488 浏览 3 评论 0原文

我有一个简单的Java项目,当我在Eclipse环境中执行它时可以使用。但是,当我尝试将其导出到可运行的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.

我读了其他建议创建subtest.mf文件的帖子,以指定我所做的主流。它放置在myprojectFolder/meta-inf/subest.mf上,其中包含以下信息:

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

我的主要类别如下:

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

有人知道我缺少什么吗?任何帮助都非常感谢。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⊕婉儿 2025-02-04 02:47:58

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

回答以评论

如果使用“可运行的JAR”,请确保选择正确的启动配置,并且在选择“运行为“ - &gt”时,启动配置成功运行; “运行配置” - > “ Java应用程序” - >您的配置 - > “跑步”

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"

忆依然 2025-02-04 02:47:58

我终于发现了问题所在,这很简单。我已经在src.main.java软件包中创建了我的概述,但是创建了该软件包(我的糟糕)为 Resources 而不是文件夹,因此Eclipse足够聪明,可以运行但是,当试图生成期望正确的Java项目结构的JAR时,它是失败的,因为确实没有guiprogram Java类,src path(SRC不是文件夹类型,而是资源)。

希望我能成功解释。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文