我如何创建一个.jar来运行命令行应用程序 [英] how do I create a .jar to run command line application
本文介绍了我如何创建一个.jar来运行命令行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为方便起见,我将使用hello world ...
For ease I'll use hello world...
public class HelloWorld{
public static void main (String [] args){
System.out.println("Hello World");
}
}
如您所料,编译并运行良好.然后制作一个Manifest.txt文件,其中包含:
Compiles and runs fine as you'd imagine. Then made a file Manifest.txt containing:
Main-Class: HelloWorld
然后跑了
jar -cfm Hello.jar Manifest.txt *.class
但是,当我双击生成的Hello.jar时,什么也没有发生.我希望控制台至少能迅速弹出... (实际上,我有一个更精致的程序等待输入)
However when I double click the resulting Hello.jar, nothing happens. I'd expect the console to pop up quickly at least... (I in fact have a more elaborate program which waits for input)
有什么想法为什么不起作用?
Any ideas why this is not working?
它正在任务管理器(Windows)中启动一个进程,但没有打开cmd
It is starting a process in the task manager (windows) but no cmd openning
推荐答案
尝试从命令行执行
java -jar /path/to/YourJar.jar
确保您具有Main-Class
条目
另请参见
这篇关于我如何创建一个.jar来运行命令行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文