2
3

More than 3 years have passed since last update.

VScodeでSpring Bootプロジェクトを作成したらBuild path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment. と表示された

Last updated at Posted at 2020-05-09

開発環境

・ホストOS: Windows10 Home ビルド19619
・ゲストOS: WSL2 Ubuntu20.04 LTS
・VScode ver 1.45.0
・openJDK 11.0.7
・Spring 2.2.7
・Maven 3.6.3

発生したエラー

・VScodeでSpringプロジェクトを作成したところ、以下のエラー(警告)が発生した

Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment. 
The compiler compliance specified is 1.8 but a JRE 11 is used

どうやら本来はJavaSE-1.8であるべきなのに11を使っているのが原因のよう。

解決法

pom.xmlを編集してJavaのバージョンを変更する。
具体的にはpom.xmlの17~20行目あたりに記載している下記のコード

<properties>
  <java.version>1.8</java.version>
</properties>

を次のように変更する


<properties>
  <java.version>11</java.version>
</properties>

これで警告が表示されなくなった。

また、Mavenの公式ドキュメントによると次のように書いても同じようにエラーを解消できるとのこと。(試してはいないが)


<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

というかデフォルトのjava.versionを今使っているJavaのバージョンに合わせてくれてもいいような・・・
うまく設定する方法があるか調べてみたい。

参考資料

diki-kezuka’s diary様
Mavenの公式ドキュメント

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3