Home > Software design >  Spring project on vscode doesn't run
Spring project on vscode doesn't run

Time:04-11

I'm working on a Spring project on GitLab with classmates. After I pulled it, I ran it on Visual Studio Code and searched "localhost:8080" on my browser but it doesn't work. It's my first time working with Spring Boot so I have no idea what's wrong.

I also got these problems :

  • Build path specifies execution environment JavaSE-11/ There are no JREs installed in the workspace that are strictly compatible with this environment.
  • The compiler compliance specified is 11 but a JRE 16 is used.
  • couldn't determine port app is running on

screenshot of my vscode

I'm really sorry if it isn't clear enough.

CodePudding user response:

The reason this is happening to you is because the compiler compliance specified when creating your spring project is 11 but are using a JRE 16 on your mac. The easiest way to fix this is to use multiple versions of Java. It works for Linux and macOS.

  • Step 1: Install SDKMAN! (Follow the steps in the documentation)

  • Step 2: Go to your term and type sdk list java to see all the versions available in SDKMAN you may notice that there are not only different version numbers but also different distribution so you can choose whatever you want in your case I recommend Install this one.JDK from Zulu version 11.0.14

  • Step 3: Install JDK from Zulu version 11.0.14 type sdk install java 11.0.14-zulu example

  • Step 4: Go to VS Code open the integrated terminal and type sdk use java 11.0.14-zulu

  • Step 5: Verify that everything changed correctly type java -version you must see openjdk version "11.0.14"

  • Step 6: reboot VS code or just the server and check it should work

CodePudding user response:

Could you try to switch the java from 11 to 16 in the pom.xml?

<properties>
    <java.version>16</java.version>
</properties>

Or

<properties>
  <maven.compiler.source>16</maven.compiler.source>
  <maven.compiler.target>16</maven.compiler.target>
</properties>

Or

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>xxx</version>
    <configuration>
      <source>16</source>
      <target>16</target>
    </configuration>
  </plugin>
</plugins>
  • Related