通过双击在命令提示符中运行.jar文件
我将从Windows 7上说IM开始。
我创建了一个.jar文件,该文件使用-java -jar myjar.jar.jar方法从命令行执行正常,
但是我追求的是能够双击JAR文件并为其打开命令提示符窗口并在命令提示符中运行,就好像我刚刚键入Java -jar myjar.jar line一样。
当我双击JAR文件时,我确实认为它正在运行,因为Java的视觉部分正在显示,但是没有命令提示窗口显示我的控制台输出。
环顾四周之后,我遇到有人说Javaw是JAR文件与没有控制台相关联的Javaw,我需要将Jar文件与Java.exe而不是Javaw.exe关联。我已经尝试过,它似乎没有用。
谁能帮忙?一步一步会很好。
I'll start of by saying Im on windows 7.
I have created a .jar file which executes fine from the command line using the - java -jar myJar.jar approach
But what I'm after is to be able to double click on the jar file and for it to open up the command prompt window and run in the command prompt as if i've just typed the java -jar myJar.jar line.
When I double click the jar file I do think it is running because a visual part of the java is appearing, but there is no command prompt window showing my console output.
After looking around I've come across people saying that javaw which is what the jar files are associated with don't have a console and that I need to associate jar files with java.exe instead of javaw.exe. I've tried this and it didn't seem to work.
Can anyone help? A step by step would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我也有同样的问题,蝙蝠文件的想法是天才,并节省了很多时间重写代码。 !
谢谢
只需将
java -jar yourfile.jar
放入记事本(如果您在Windows上),将其另存为title.bat.bat
,然后放入与JAR的同一文件夹中。普雷斯托!公众开放的计划。
I had the same question and the bat file idea was genius and saved me a lot of time rewriting code. Thanks!(I would have upvoted,but apparently I don't have enough rep.)
Batch (or Bat) files are super easy to make.
Just put the
java -jar YourFile.jar
into notepad (if you're on windows), save asTitle.bat
, and put into the same folder as your jar.presto! a program open-able by the general public.
这是不可能的。您可以从应用程序本身打开控制台是OS依赖的。如果需要打开控制台,则必须像已经这样做一样从中运行该应用程序。
This is IMHO not possible. You could open the console from the application itself, but that is OS-dependent. If you need the console open, you have to run the application from it as you already do.
如果要显示命令行,则必须使用命令行启动JAR。
Java -jar myjar.jar
If you want to display the command line you have to launch your jar with the command line.
java -jar MyJar.jar
我会做类似的事情:(
在使用JRE 1.6的Widows XP中进行测试,为了支持其他OSS,您应该验证每个OS的路径,然后选择适当的控制台仿真器(
xterm
,gnome-terminal
...(检查存在和偏爱...)))))I would do something like this:
(Tested in Widows XP with JRE 1.6, to support other OSs you should verify the path for each OS and select the appropriate console emulator (
xterm
,gnome-terminal
... (check for existance and preference...)))另外,我建议使用此内容创建一个BAT文件:
这将启动您的JAR,并自动打开命令提示符,所有这些都可以从简单的双击BAT文件中。
(BAT文件需要与JAR文件相同的文件夹,否则您需要指定通往罐子的路径,而不仅仅是JAR名称)
Alternatively I suggest creating a bat file with this content :
This will launch your jar as well as open the command prompt automatically, all from a simple double click on a bat file.
(The bat file needs to be in the same folder as your jar file, else you need to specify the path to the jar, not just the jar name)
对于初学者来说,这是最简单的解决方案:
写这两行:
将该文件另存为“ name” .bat
(当然,这是这样)新创建的.bat文件必须与.class同一文件夹)
This is the easiest solution for beginners:
write this two lines:
save that file as "name".bat
(of course this new created .bat file must be in the same folder as the .class)
没有可执行罐的控制台。您需要将该输出放入GUI中。
No there wouldn't be a console for an executable Jar. You'll need to put that output in the GUI.
检查您
主类:yourmainClasshere
如果该字段消失了,则打开您的原始清单。
Main-Class:YourMainClasshere 必须以新的线或马车返回
警告:文本文件必须以新的线路或运输返回结尾。如果不以新的线或运输返回结束,则最后一行将无法正确解析。
Check your MANIFEST.MF
Main-Class: YourMainClassHere
If this field dissapeared then open your original MANIFEST.txt for this point:
Main-Class: YourMainClassHere must end with a new line or carriage return
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.