1

I recently got a new PC and imported the projects I work on in my workspace.

After that I noticed that one of the projects has the wrong JDK compliance level. I wanted to change away from "Use compliance from execution enirvonment 'JavaSE-1.7' on the 'Java Build path'" settings but can't change it. Clicking "apply" doesn't change a thing. But with the other projects it is possible. (But they have "Use compliance from execution enirvonment 'J2SE-1.5' on the 'Java Build path'")

What am I doing wrong? My colleague installed everything the same way I did and she can change it.

The problem is that I can't start my non-working problem because of this wrong version.

PS: I'm on Spring Tool Suite 3.8.4

DonJoe
  • 11
  • 2
  • 1
    Did you look at [this answer](https://stackoverflow.com/questions/24947844/why-wont-eclipse-switch-the-compiler-to-java-8/37564720) first? – MarsAtomic Sep 04 '18 at 19:19
  • I don't know how to apply this to my situation. It's strange that it works for the other imported projects... – DonJoe Sep 04 '18 at 20:33
  • did you take a look at the preferences for the configured Java JREs? There is a sub-entry that allows you to define which JRE to use for which execution environment. Maybe there is something missing? – Martin Lippert Sep 05 '18 at 08:13
  • It depends on the project. Maven project? Gradle project? For maven and gradle project you shouldn't try to modify these settings directly but rather make sure that the compiler source/target level is set correclty in the pom or build.gradle and rely on the tooling (m2e / buildship) to configure the Eclipse project. This is really unintuitive to most users (and arguably its not the user's fault, but just an awkward ui desing), but you should *not* change these project settings directly for maven/gradle projects. – Kris Sep 07 '18 at 16:51
  • @Kris Yes it's a Maven project. The strange thing is, that it keeps changing but it isn't in the project's pom file. – DonJoe Sep 08 '18 at 20:07
  • @DonJoe "The strange thing is, that it keeps changing but it isn't in the project's pom file" well...that's probably why. If you don't put anything in the pom to set it explicitly, maven/m2e will conservatively pick some ancient version of java as 'target' by default. So make sure to add a proper declaration of the java level you want in the pom, do a 'Maven Update Project' from the context menu in Eclipse, and it should set the target correctly. – Kris Sep 10 '18 at 16:30

1 Answers1

1

Assuming your project is a maven project. You should set the Java source and target levels via your pom.xml file. Something like this:

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

Once you've done that... If m2e (eclipse maven tooling) does not automatically update your project's compliance level in Eclipse, you may need to tell m2e to update project configuration via project's context menu:

  • Right click the project.
  • Select menu 'Maven >> Update Project'

References:

Kris
  • 3,898
  • 1
  • 23
  • 32