[英]how do I create a .jar to run command line application
For ease I'll use hello world... 为方便起见,我将使用hello world ...
public class HelloWorld{
public static void main (String [] args){
System.out.println("Hello World");
}
}
Compiles and runs fine as you'd imagine. 按照您的想象编译并运行正常。 Then made a file Manifest.txt containing:
然后制作了一个文件Manifest.txt,其中包含:
Main-Class: HelloWorld
then ran: 然后跑了:
jar -cfm Hello.jar Manifest.txt *.class
However when I double click the resulting Hello.jar, nothing happens. 但是,当我双击生成的Hello.jar时,没有任何反应。 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? 任何想法为什么这不起作用?
It is starting a process in the task manager (windows) but no cmd openning 它在任务管理器(窗口)中启动一个进程,但没有cmd打开
make sure the Main-Class
line in the manifest file is followed by an empty line! 确保清单文件中的
Main-Class
行之后是空行!
Hard to believe, but the specification mandates that each line of the manifest file, including the last one, be terminated by a newline character. 难以置信,但是规范要求清单文件的每一行(包括最后一行)都以换行符终止。
EDIT: 编辑:
If the problem is just with double clicking, try (assuming Windows): 如果问题只是双击,请尝试(假设Windows):
assoc .jar=jarfile
ftype jarfile="<JRE directory>\bin\javaw.exe" -jar "%1" %*
(use these without argument to check the actual settings) (使用不带参数的这些来检查实际设置)
Your clients will need the JRE to run the Java program - the above settings normally are done by the installation of the JRE. 您的客户端将需要JRE来运行Java程序-上述设置通常是通过安装JRE完成的。
EDIT2: EDIT2:
Use java.exe
instead of javaw.exe
to see the standard console (if your program does not have a GUI) 使用
java.exe
而不是javaw.exe
来查看标准控制台(如果您的程序没有GUI)
Try executing from command line 尝试从命令行执行
java -jar /path/to/YourJar.jar
Make sure you have Main-Class
entry 确保您有
Main-Class
条目
See Also 也可以看看
The manifest needs to be named MANIFEST.MF and it needs to reside in a top level directory called META-INF. 清单需要命名为MANIFEST.MF,它需要驻留在名为META-INF的顶级目录中。 Then it should work.
然后它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.