在VScode中运行Java程序

huangapple go评论91阅读模式
英文:

Running a java program in VScode

问题

我最近开始使用VScode编写Java代码。我遇到了一个简单的问题。问题是我不希望输出像这样。换句话说,我不希望程序在终端中运行,如下所示。我只希望语句被单独打印出来。在这里,我只想要打印出(Hello world),没有其他内容。我搜索了如何运行Java程序,并发现输出必须出现在"OUTPUT"或"DEBUG CONSOLE"中。

有人可以帮助我吗?注意:我已经安装了Java 14以及在VScode中为Java所需的所有扩展。

英文:

I start coding java with VScode recently. I have a simple problem. The problem is that I do not want the output to be like that. In other words, I do not want the program to run in the terminal as shown below. I just want the statements to be printed alone. Here, I just want (Hello world) only to be printed with nothing else. I googled how to run a java program and I found that the output must appear in either OUTPUT or DEBUG CONSOLE.

Can anyone please help me?. NOTE: I installed java 14 as well as all needed extensions in VScode for java.

在VScode中运行Java程序

答案1

得分: 1

如果您的代码不需要输入数据,您可以在 launch.json 中添加以下内容:

"console": "internalConsole"

默认值为:

"console": "integratedTerminal"

我不建议安装 'Code-Runner' 扩展,因为它会在与 Java 文件相同的文件夹下编译 Java 文件,并将它们混在一起。

我建议您熟悉输出,输出可以提供有用的信息,让您知道 Visual Studio Code 实际上在做什么。如果您遇到问题,您将需要这些信息来帮助您解决问题。

英文:

If your code needn't input data, you can add this in the launch.json:

"console": "internalConsole"

The default value is:

"console": "integratedTerminal"

I do not suggest install the 'Code-Runner' extension, because it will compile the java file under the same folder of the java file, and mix them up.

And I recommended you to get used to the outputs, the outputs can provide useful information, let you know what's exactly the vscode does. If you run into some problems, you will need this information to help you to solve the problem.

答案2

得分: 0

在这种情况下,您只需按下Command F5(Mac)或其他键绑定(https://code.visualstudio.com/docs/getstarted/keybindings)。 这将在您的IDE中运行程序。否则,您可以创建一个launch.json文件来配置调试。

英文:

In this case, you can just press Command F5 (Mac) or other keybindings (https://code.visualstudio.com/docs/getstarted/keybindings). This runs the program in your IDE. Otherwise, you can create a launch.json file to configure your debugging.

答案3

得分: 0

你想要做的是按照在 Visual Studio Code 中运行和调试 Java 程序中的指示设置一个 launch.json 文件。这将定义代码的启动方式以及调试会话的输出位置。您可以通过添加并配置Microsoft Java 调试器的用户设置来自定义出现的调试输出。

英文:

What you want to do is follow the instruction in Run and Debug Java in VS Code to setup a launch.json file. This defines how your code is launched and where the output from that debug session goes. You can customize the Debug output that appears by adding and configuring the User Settings for the Microsoft Java Debugger

答案4

得分: 0

以下是您可以做的一些事情:

如果您已安装了所有必要的扩展包,那么编辑器会在代码本身上显示一个运行和调试类的选项。 (在Linux上工作时很少见,但有时会出现)

否则,在终端中键入javac <name.java>(输出将显示在终端选项卡中)

或者安装在VS Code Marketplace中可用的代码运行器扩展(这将在输出选项卡中轻松显示结果)

英文:

Here are some things which you can do:

If you have installed all necessary extension packs, then the editor would display an option to Run & Debug the class on the code itself. (rare cases but it appeared while working in Linux)

Else type javac &lt;name.java&gt; in the terminal(output will be displayed in Terminal tab)

Or install the code runner extension which is available in VS Code Marketplace (that would display results in output tab easily)

huangapple
  • 本文由 发表于 2020年8月4日 21:17:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63247749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定