在我的VSCode工作区中设置JRE时遇到了一些问题。我认为问题是在我的settings.json中正确设置了我的java.home,但我仍然收到这个错误:
Build path specifies execution environment JavaSE-10. There are no JREs installed in the workspace that are strictly compatible.
我在这里查看了答案(Warning - Build path specifies execution environment J2SE-1.4),但解决方案是针对Eclipse的,而不是针对VSCode的。
我想这是因为JRE指定了Java10,而我使用的是Java11。
关于如何为VSCode设置JRE有什么建议吗?
另外,这是我正在使用的java版本和我的设置。
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
11.0.1, x86_64: "Java SE 11.0.1" /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home以及我在VSCode中的java.home设置:
"java.home": "/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home"
发布于 2020-02-15 06:07:45
在我的例子中,我在VSCode中将Maven设置为Java的构建环境。对于maven,我发现pom.xml中的一个build属性被设置为Java version1.8,它比我使用的版本更早,即1.11。一旦我按如下所示更新了该属性,警告就消失了。
<properties>
<java.version>1.11</java.version>
</properties>发布于 2020-09-29 10:43:35
要完全删除警告/错误,我认为您需要:
JavaSE-10“作为settings.json中java.configuration.runtimes阵列中的name
考虑到这个问题是在2018年提出的,对于我当前版本的VS代码(1.49.2),它将在“兼容性”模式下使用更高的JDK版本,类似的消息是just warnings。
因为我自己弄清楚和配置所有东西都有一些困难,这在谷歌搜索中仍然排名靠前,所以我记录了设置java.configuration.runtimes的完整说明(特别是关于Windows和WSL),因为对我来说,最好不要使用java.home设置更改整个默认JDK (特别是因为如果使用JDK版本低于11的话,这可能也会破坏JSL,如下所述)。
根据以下内容:
- the Java Language Server requires Java SE 11 or later- the `java.home` setting should be used to point to the JDK used by the JLS, and also code compilation if not explicitly overridden
- there is a _precedence_ for the variables referenced, i.e.:
- the `java.home` setting in VS Code settings (_workspace_ then _user_ settings)
- the `JDK_HOME` environment variable
- the `JAVA_HOME` environment variable
- on the current system path- to compile against a different JDK, set the `java.configuration.runtimes` in the respective `settings.json` (i.e. workspace and/or user): "java.configuration.runtimes": [ { "name": "JavaSE-1.8", "path": "/path/to/jdk-8", }, { "name": "JavaSE-11", "path": "/path/to/jdk-11", }, { "name": "JavaSE-14", "path": "/path/to/jdk-14", "default": true }, { "name": "JavaSE-15", "path": "/path/to/jdk-15", "default": true }, ]- **NOTE**: I am unsure why the example has _two_ `default`s, but the example from their own [Wiki](https://github.com/redhat-developer/vscode-java/wiki/JDK-Requirements#setting-the-jdk) and the [VS marketplace description](https://marketplace.visualstudio.com/items?itemName=redhat.java#setting-the-jdk) have only one.要编辑settings.json以添加(或编辑) java.configuration.runtimes设置:
settings.json如果返回"No Settings (screenshot showing 3 environments)settings.json文件(根据上面的说明,打开相应的settings.json并输入您的自定义java.configuration.runtimes片段(如上所示),确保仅使用允许的“name”(如上所述)并使用正确的路径(如果是Windows或Linux路径,请考虑后者适用于WSL)settings.json编辑窗口并设置您的Maven pom.xml的maven.compiler.source和maven.compiler.target,同步项目的Java类路径和配置<代码>C55(这也将相应地更新您的EclipseD56、D58和<代码>D59(如果它也存在)<代码>H260<代码>G261来自settings.json的示例java.configuration.runtimes代码片段
"java.configuration.runtimes":{“名称”:“JavaSE1.8”,“路径”:"C:\Program Files\Java\jdk1.8.0_261“},{”名称“:"JavaSE-12",”路径“:"C:\Program Files\Java\jdk-12.0.1”}
"java.configuration.runtimes":{“名称:”:"JavaSE-1.11",“路径”:"/usr/lib/jvm/java-11-openjdk-amd64“},{”名称“:"JavaSE-1.8",”路径“:"/usr/lib/jvm/java-8-openjdk-amd64”}
发布于 2021-07-19 11:15:46
我刚刚改变了:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>至:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>1.7 -> 1.8
其中1.8是我的java版本
在您的终端中:
java -version我将得到:
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)我使用的是java 1.8,所以它必须是1.8
如果您使用的是1.11,那么它必须是1.11,依此类推……
https://stackoverflow.com/questions/53817951
复制相似问题