使用 Microsoft Visual Studio Code 进行 Java 编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42340927/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:04:37  来源:igfitidea点击:

Java Programming with Microsoft Visual Studio Code

javavisual-studio-code

提问by ???

I downloaded language support for Java by Red Hat in Microsoft Visual Studio Code, enter image description here

我在 Microsoft Visual Studio Code 中下载了 Red Hat 对 Java 的语言支持, 在此处输入图片说明

but I got a problem as shown in the above picture.

但我遇到了如上图所示的问题。

So I tried to set my JDK path in the settings.jsonfile in VSCode:

所以我尝试settings.json在 VSCode的文件中设置我的 JDK 路径:

"java.home": "C:/ProgramFiles/Java/jdk1.8.0_111"

But the problem is still not solved.

但问题仍然没有解决。

Do you know how to solve this problem?

你知道如何解决这个问题吗?

回答by FrederikVH

You have to restart VS Code after entering the java.home variable in the settings file.

在设置文件中输入 java.home 变量后,您必须重新启动 VS Code。

Alternatively, setting that variable isn't even required. You can remove it from your settings and VS Code will automatically check your user/system environment variables for JDK_HOME and JAVA_HOME.

或者,甚至不需要设置该变量。您可以从设置中删除它,VS Code 将自动检查 JDK_HOME 和 JAVA_HOME 的用户/系统环境变量。

See "Setting the JDK" at https://marketplace.visualstudio.com/items?itemName=redhat.java

请参阅https://marketplace.visualstudio.com/items?itemName=redhat.java 上的“设置 JDK”

For information on how to set the environment variables, see Environment variables for java installation

有关如何设置环境变量的信息,请参阅java 安装的环境变量

回答by Zaher88abd

you should change the path to be like this:

您应该将路径更改为如下所示:

"java.home":"C:\Program Files\Java\jdk1.8.0_111"

回答by profimedica

My Visual Studio Code is set to use the 32 bit version of JDK

我的 Visual Studio Code 设置为使用 32 位版本的 JDK

A default java.exe is installed in your %SYSTEMROOT%\System32

默认的 java.exe 安装在您的 %SYSTEMROOT%\System32 中

Check java version from command line:

从命令行检查 java 版本:

java -version

版本

You might need to add your version to PATH:

您可能需要将您的版本添加到PATH

set PATH=%PATH%;C:\Program Files (x86)\Java\jdk1.8.0_111\bin

set PATH=%PATH%;C:\Program Files (x86)\Java\jdk1.8.0_111\bin

And set your system JAVA_HOME:

并设置您的系统JAVA_HOME

setx -m JAVA_HOME "C:\Program Files (x86)\Java\jdk1.8.0_111"

setx -m JAVA_HOME "C:\Program Files (x86)\Java\jdk1.8.0_111"

Restart cmd and try:

重新启动cmd并尝试:

echo %JAVA_HOME%

回声%JAVA_HOME%

Restart Visual Studio Code and be happy.

重新启动 Visual Studio Code 并感到高兴。

Use setinstead of setxfor local user.

使用set而不是setx本地用户。

回答by nevyn

In case this question is still open.

如果这个问题仍然存在。

Try placing a space between the words, Program and Files, so it reads:

尝试在单词 Program 和 Files 之间放置一个空格,使其显示为:

"C:/Program Files/Java/jdk1.8.0_131"

“C:/Program Files/Java/jdk1.8.0_131”

回答by Uma

If you are using bash from VSCode, should use:

如果您从 VSCode 使用 bash,则应使用:

export JAVA_HOME=/c/Program\ Files/Java/jdk1.8.0_172

export JAVA_HOME=/c/Program\ Files/Java/jdk1.8.0_172

You can use this in the terminal there.

您可以在那里的终端中使用它。

回答by Diwakar Chauhan

You only need to put the space in between Program and files like:

您只需要在 Program 和 files 之间放置空格,例如:

java.home :- "C:/Program Files/Java/jdk1.8.0_111"

java.home :- "C:/Program Files/Java/jdk1.8.0_111"

回答by Aldo Biturku

try to change path as follow:

尝试更改路径如下:

"java.home":"C:/Program Files/Java/jdk1.8.0_202"

Make attention to the space in "Program Files" in the path.

注意路径中“Program Files”中的空格