Eclipse可以将Java文件导出到.Jar文件中,但仍会遇到错误



基本上,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时,问题得到了解决。显然,它是在java -jar之后将文件拖到终端后工作的,今天没有出现任何错误。Tysm!

最新更新