如何使我的Java应用程序打开控制台/终端窗口?

问题描述:

有什么方法可以使可执行文件.jar双击时打开命令行?

Is there any way I can make an executable .jar that will open up the command line when double clicked?

我正在制作基于文本的冒险游戏。截至目前,它只是带有房间的迷宫。最终它将变得更大,更深入,但是现在我只想了解基本结构。无论如何,要完成这项工作,我一直在从System.out.printf命令和java.util.Scanner获取输出和输入。到目前为止,所有功能都运行良好,但是当我尝试将其发送给不知道如何或者不想从命令行运行程序的其他人时,我已经意识到自己会遇到问题。

I'm making a text-based adventure game. As of right now it is just a maze with rooms. Eventually it is going to be much bigger and more in depth but for now I just want to get the basic structure down. Anyways, to make this work I've been getting output and input from the System.out.printf command and the java.util.Scanner. It's all working beautifully so far but I've realized I'm going to run into a problem when I try to send this to other people that don't know how or just don't want to run the program from the command line.

如果要完全控制,则可以在Swing中实现一个Console窗口,该窗口具有您现在所拥有的功能。

If you want full control, you can implement a Console window in Swing which does what you have now.

如果您无法打开所说的窗口(如果没有头),或者用户在命令行中要求它,那么只需默认为当前行为即可。

If you cannot open said window (if headless) or the user asks for it on the command line, then just default to your current behaviour.