Maven "build path specifies execution environment J2SE-1.5", even though I changed it to 1.7

109,822

Solution 1

  1. Right-click on your project
  2. Click Properties
  3. Click the "Java Compiler" option on the left menu
  4. Under JDK compliance section on the right, change it to "1.7"
  5. Run a Maven clean and then Maven build.

Solution 2

All of the answers above may work for the time being but whenever you run maven on the command line or Maven → Update project… the JDK will be reset, this was also the question as I understand it.

To fix this for good add the following code to your pom file. Remember to do a Maven → Update project… afterwards or mvn clean compile at the command line.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>

    </pluginManagement>
</build>

Solution 3

I know this is an old topic. I had the same problem. I tested all the answers about this topic. And nothing worked here... but i found another solution.

Go to pom->overview and add these to you properties:

  • Name: "maven.compiler.target" Value: "1.7"

and

  • Name: "maven.compiler.source" Value: "1.7"

Now do a maven update.

Solution 4

For imported maven project and JDK 1.7 do the following:

  1. Delete project from Eclipse (keep files)
  2. Delete .settings directory, .project and .classpath files inside your project directory.
  3. Modify your pom.xml file, add following properties (make sure following settings are not overridden by explicit maven-compiler-plugin definition in your POM)

    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    
  4. Import updated project into Eclipse.

Solution 5

I'm using Juno 4.2 with latest spring, maven plugin and JDK1.6.0_25.

I faced same issue and here is my fix that make default after each Eclipse restart:

  1. List item
  2. Right-click on the maven project
  3. Java Build Path
  4. Libraries tab
  5. Select current wrong JRE item
  6. Click Edit
  7. Select the last option (Workspace default JRE (jdk1.6.0_25)
Share:
109,822
bheussler
Author by

bheussler

Updated on May 11, 2020

Comments

  • bheussler
    bheussler about 4 years

    In Eclipse Juno, I installed the latest m2e plugin (1.2.20120903-1050). In preferences, I have added jdk1.7.0_11 in Java -> Installed JREs -> Add, and then specified the location (C:\Program Files\Java\jdk1.7.0_11). When I create a new Maven project and run it, I get a warning:

    Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.

    I am not sure how to resolve this.

    I believe it is a Maven problem because I do not have this error when I run normal Java projects. I read here that I should change the "maven-compiler-plugin.pom" and change the source and target from 1.5 to something more appropriate. In my case, 1.7. I have done this, but I still get the warning.

  • bheussler
    bheussler over 11 years
    Thank for the help. In addition to this, I also had to right-click JRE System Library -> Properties -> and change execution environment to JavaSE-1.7
  • Neel
    Neel about 11 years
    @Brett VanderVeen : How does the Maven plug-in pick up J2SE 1.5 by default? Is there a way to change the default by making any change to the settings.xml for example?
  • Brett VanderVeen
    Brett VanderVeen about 11 years
    I think you can change the default by going to "Java > Installed JREs > Execution Environments" and checking the box next to the one you want set to the default.
  • Adrian
    Adrian over 10 years
    This is the only solution. Better tell Maven to use the correct compiler and not Eclipse. This way you also make sure, your team mates don't get into the same trouble.
  • Gangnus
    Gangnus over 10 years
    And after step 5 you are free to repeat all from 1. Ad infinitum... -1
  • Gangnus
    Gangnus over 10 years
    Also you forgot to rebuild the maven project at the end. And after that all returns to the previous state. -1.
  • Gangnus
    Gangnus over 10 years
    Won't help at all. After Maven rebuild back to JavaSE-1.5. BTW, for 1.7 java you need maven-compiler-plugin version starting from 2.6.
  • Gangnus
    Gangnus over 10 years
    I am sorry, it works. It is exactly THE solution. Please, change the version to contemporary 3.1, so I can change downvote to upvote.
  • ProfVersaggi
    ProfVersaggi over 10 years
    One extra addition ... none of the above will work if you don't actually have the Java JRE7 installed and referenced in Eclipse. Assuming you actually do have it installed but not referenced in Eclipse - then the following might be necessary: Go into: ==> Window, Preferences, Java, Installed JRE's ==> Add the JRE paths for Java JRE7: "C:\Program Files\Java\jre7"
  • javabeangrinder
    javabeangrinder over 10 years
    True, especially when concerning Eclipse. Outside the IDE it will work though. AS long as the appropriate Java is installed that is. Good point!
  • Jaroslav Záruba
    Jaroslav Záruba about 10 years
    Sadly Maven seems to be unaware of what does one set as default JRE. I have 1.7 as the default exec. env. yet my project keeps switching to JRE 1.5. Configuring the maven-compiler-plugin works tho. :)
  • Brett VanderVeen
    Brett VanderVeen about 10 years
    Right @JaroslavZáruba, I answered as I did because the question stated that he already changed the "maven-compiler-plugin" targetJdk to 1.7. In your case, if you were to have read the complete question, you have have received the answer you were looking for.
  • Alphaaa
    Alphaaa almost 9 years
    Worked great for me as well. No need to install the compiler plugin.
  • Yohn
    Yohn over 8 years
    It's the best answer for this question.
  • Yohn
    Yohn over 8 years
    This solution works well at most circumstances, but not on my new PC. I cannot find out what's wrong with newest maven, but @Torisuta 's answer actually works.
  • javabeangrinder
    javabeangrinder over 8 years
    I think that is great for you. However that solution is IDE dependent.
  • eeezyy
    eeezyy over 8 years
    thank you, that's a great solution and all without the maven-compiler-plugin.
  • peterh
    peterh over 8 years
    The m2e will change this setting back to the version specified in the pom.xml on the first config refresh. This is not the correct answer, @javabeangrinder has right.
  • Brett VanderVeen
    Brett VanderVeen about 8 years
    @javabeangrinder As OP stated in the question... He already added those details to the POM. Next time read the question in its entirety.
  • Brett VanderVeen
    Brett VanderVeen about 8 years
    @Adrian As OP stated in the question... He already added those details to the POM. Next time read the question in its entirety.
  • Adrian
    Adrian about 8 years
    @BrettVanderVeen Is just second the pom way of defining it and not using the accepted answer, which is wrong. This answer is clearly "Maven -> Update project..." with a little more explanation of pom configuration.
  • Brett VanderVeen
    Brett VanderVeen almost 8 years
    @peterh Again... read the entire question... the OP states they changed their pom.xml maven-compiler-plugin configuration to target "1.7". At the time there was a bug in eclipse m2e plugin to where it wouldn't immediately recognize the target jdk defined in the pom and this allowed you to workaround the warning.
  • peterh
    peterh almost 8 years
    @BrettVanderVeen O.k., I will check this and change my votes if it is needed.
  • Brett VanderVeen
    Brett VanderVeen almost 8 years
    @Adrian I agree. At the time the m2e plugin had a bug recognizing the change to the pom target jdk.
  • Hack-R
    Hack-R over 7 years
    Gives cvc error invalid content starting with pluginManagement
  • Zack
    Zack about 7 years
    Not necessary to delete project and re-import. Just use ALT + F5 to update the maven project.
  • David A. Gray
    David A. Gray almost 7 years
    If this is the only solution, then it's an incomplete solution, because I have my POM configured exactly as shown, yet "Description Resource Path Location Type Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. OAuth SFDC GAE Build path JRE System Library Problem" persists in my environment, with Eclipse Neon.
  • Eduardo Pascual Aseff
    Eduardo Pascual Aseff over 4 years
    Problem Solved..Cheers!!