我无法通过双击执行 .jar 文件

I can't execute a .jar file by double-clicking

我一遍又一遍地尝试让这个愚蠢的 .jar 文件执行,它除了打印文本外什么都不做。我需要一个 GUI 吗?我在 mac.

代码很简单...

public class test
{
    public static void main(String args[])
    {
        System.out.println("This is a test!");
        System.out.println("HelloWorld!");
    }
}

我编译了 test.java 文件,将 test.class 放入我的桌面,创建了一个 manifest.txt 文件以确保 jar 知道 test.class 是主文件。我写了

Main-Class: test

进入manifest.txt文件

然后我进入了

[Macintosh:~] mitchellhowe% cd Desktop
[Macintosh:~/Desktop] mitchellhowe% jar -cvmf manifest.txt Test.jar test.class

终端回复

added manifest
adding: test.class(in = 341) (out= 186)(deflated 45%)

并创建了 Test.jar 文件 ==> Proof of Test.jar creation

然而,当我双击执行时,它给了我 this

我该如何解决这个问题?它只需要一个 GUI 还是我做错了什么?

****PS****

I am relatively new to programming, I was just curious about how to create an executable jar file. So please put any instructions/criticism in a simplistic format and I will try and reply. ALSO, I want it so I can double-click the file to execute, not order something into terminal (I already know how to run from terminal). Thanks for any help!

您的程序不包含 GUI 框架,因此无法打开。查看 JavaFX 或 Swing。我推荐 JavaFX,因为他们新的 SceneBuilder 应用程序,它使得构建基于 GUI 的应用程序非常容易学习。

您一语中的是——您需要一个 GUI。尝试将 System.out.println 替换为 JOptionPane.showMessageDialog(null, "Mitch says...", "Hello world!", JOptionPane.PLAIN_MESSAGE); 并添加 import javax.swing.JOptionPane; 以及其他导入。