1

The problem is that 'mvn clean install' fails inside visual studio code for the following reason 'Fatal error compiling: invalid target release: 11 .'

The error is clear enough. I have created an appropriate bat file to change my used jdk to 11, to match the version in my pom. This bat file does what it's supposed to do, which has allowed me to run 'mvn clean install' from the command prompt without errors.

The problem is that, inside vsc, from the powershell, after running my bat file, I get the following, when I enquire about the java version:

PS C:\Users\xxxx\programming\xxxxx\xxx-customer-project> java -version
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)

and 'mvn clean install' fails for the same, above reason. How can I also change those two pointers from v18.9?

HellishHeat
  • 2,280
  • 4
  • 31
  • 37
  • Restarting VSCode does not fix the issue? I guess the Powershell does not refresh env variables properly. – Jmartnz Jan 07 '22 at 09:50
  • Run `java -verison` in Powershell, the result is got from **Environment Variables--> PATH**, you can set jdk18.9 as `JAVA.HOME` and move it up in PATH. then restart VS Code to make this change effective. – Molly Wang-MSFT Jan 10 '22 at 03:11
  • A restart of vs code hasn't had an effect. The current jdk version is 17, so I'm unsure what 18.9 refers to. Also, above is the output, of running 'java -verison' inside powershell. – HellishHeat Jan 11 '22 at 09:02
  • @HellishHeat. You may move jdk11 up in **PATH** and change jdk version in `pom.xml`, this works in my project that change jdk version successfully. – Molly Wang-MSFT Jan 12 '22 at 08:46
  • 1
    Try jenv (for Windows) https://github.com/FelixSelter/JEnv-for-Windows once you install it, you can set the jdk version for that project's directory. Then when someone runs java in that sub-tree it will use that version. – BillRobertson42 Jan 18 '22 at 17:28

0 Answers0