【发布时间】: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得到了什么。