【问题标题】:Eclipse Can Export A Java File Into A .Jar File But Keeps Running Into ErrorsEclipse 可以将 Java 文件导出到 .Jar 文件中,但总是遇到错误
【发布时间】:2021-08-02 17:47:34
【问题描述】:

基本上,Eclipse 不能真正导出可执行的 java 文件。每当它作为 .jar 文件导出并打开时,它会显示:

'无法启动 JAVA Jar 文件。 检查控制台是否有可能的错误消息。'

这是代码,忽略“?”分数。他们有实际的文本,那些只是替代品。

private JFrame frame;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Firstone window = new Firstone();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public Firstone() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(50, 50, 470, 100);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    JButton btnNewButton = new JButton("????");
    btnNewButton.setBounds(190, 40, 76, 29);
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    frame.getContentPane().setLayout(null);
    
    JLabel lblNewLabel = new JLabel("???");
    lblNewLabel.setBounds(18, 18, 432, 16);
    frame.getContentPane().add(lblNewLabel);
    frame.getContentPane().add(btnNewButton);
}

}

我目前停留在这个过程中,并且已经尝试了几乎所有 Youtube 论坛帖子的教程,但找不到合适的解决方案。 计算机是 MacBook,运行版本 macOS Mojave 10.14.6

【问题讨论】:

  • “检查控制台是否有可能的错误消息。” 表示您应该通过java -jar <file>.jar 在命令行上运行它并检查可能的错误消息。请在错误消息旁边不仅提供代码 sn-ps,还提供complete minimal reproducible example。也请告诉你java -version 得到了什么。

标签: java eclipse ide


【解决方案1】:

尝试执行java -jar <file>.jar 时,问题已解决。显然,在java -jar 之后将文件拖入终端后它可以工作,并且今天没有出现任何错误。太棒了!

【讨论】:

    猜你喜欢
    • 2010-09-30
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多