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

标签 java macos jar terminal executable-jar

我一遍又一遍地尝试让这个愚蠢的 .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。尝试将 System.out.println 替换为 JOptionPane.showMessageDialog(null, "Mitch says...", "Hello world!", JOptionPane.PLAIN_MESSAGE); 并添加 import javax.swing .JOptionPane; 以及其他导入。

关于java - 我无法通过双击执行 .jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33769203/

相关文章:

objective-c - OSX 中的数据加密和解密

c++ - 在 Matlab 中使用 OS X 编译/混合 imrender 函数时出错

java - pack200可以用来压缩class文件在jdk 1.4上运行吗?

java - 按部首组织的汉字索引。斯坦福核心自然语言处理

macos - 进行快速用户切换时在 OSX 上运行脚本

java - 在类路径中指定 log4j

java - 如何将具有不同值的相同对象生成到 ArrayList 中?

java - 使用 Android Studio 重命名和应用程序 ID

java - JPA合并无法更新表中的值

java - 如何在servlet init()方法中编写request.getRemoteHost()方法?