Java 在控制台中运行 Jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1619196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Jar in Console
提问by Nick
I am writing a java applicaiton that outputs strings via System.out and I just want to know how to run this application outside my IDE. I have an executable jar. What does one do to see this output in a console?
我正在编写一个通过 System.out 输出字符串的 java 应用程序,我只想知道如何在我的 IDE 之外运行这个应用程序。我有一个可执行的 jar。要在控制台中看到此输出,该怎么办?
采纳答案by Malaxeur
回答by Carlos
If I understood what you want,java -jar JarFile.jar
should work fine.
如果我明白你想要什么,java -jar JarFile.jar
应该可以正常工作。
回答by Joel
As others have suggested:
正如其他人所建议的:
java -jar JarFIle.jar
Note this requires you to set the main class entry point
请注意,这需要您设置主类入口点
If you don't/can't set Main-Class then you would do:
如果你不/不能设置 Main-Class 那么你会这样做:
java -cp JarFile.jar package.Classname
Additionally if you associate jar file types with your JRE then double click should work too.
此外,如果您将 jar 文件类型与 JRE 相关联,那么双击也应该有效。
回答by Joshua Bomba
I know this is old but I would like to help future people
我知道这是旧的,但我想帮助未来的人
You can also make another file next to it and just double click on it example:
您还可以在它旁边创建另一个文件,然后双击它,例如:
Windows: anynameyoulike.bat
Windows:anynameyoulike.bat
Linux: anynameyoulike.sh(Not sure this works but it should)
Linux:anynameyoulike.sh(不确定这是否有效,但应该)
and in that file add
并在该文件中添加
java -jar JarName.jar
java -jar JarName.jar
回答by Mahender Ambala
jar -tf JarName.jar
It will give list files in jar
它将在 jar 中给出列表文件
Drive://Jarlocation> java -jar jarName.jar
it will execute your jar from console
它将从控制台执行您的 jar
回答by WesternGun
Actually, you must run it from cmd.exe
to see the console, if you're using Windows. (Maybe Terminal.exe
of Linux does the same) You cannot just double-click the jar
, even if you enable Console in Control Panel- Java- Advanced.
实际上,cmd.exe
如果您使用的是 Windows,则必须运行它才能看到控制台。(也许Terminal.exe
Linux 也会这样做)您不能只双击jar
,即使您在Control Panel- Java- 中启用了 Console Advanced。
Now, to run it, use cd
to enter the folder where you put the jar, and:
现在,要运行它,请使用cd
进入放置 jar 的文件夹,然后:
java -jar name_of_your_jar.jar
You can see it all now.
你现在可以看到这一切。
To output the text, right-click on the top-left icon of the cmd
window, and Edit- Mark, drag to select text, Enterto copy it.
要输出的文本,上的左上角图标,用鼠标右键单击cmd
窗口,Edit- Mark,拖动来选择文本,Enter将其复制。