我一遍又一遍地尝试让这个愚蠢的 .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/