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

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.

This question is related to java eclipse maven m2eclipse

The answer is


I got an error in Eclipse Mars version as "Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.

To resolve this issue, please do the following steps, "Right click on Project Choose Build path Choose Configure Build path Choose Libraries tab Select JRE System Library and click on Edit button Choose workspace default JRE and Finish

Problem will be resolved.


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>

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.


When creating a maven project in eclipse, the build path is set to JDK 1.5 regardless of settings, which is probably a bug in new project or m2e.


I was facing the same issue. In pom.xml I have specified maven compiler plugin to pick 1.7 as source and target. Even then when I would import the git project in eclipse it would pick 1.5 as compile version for the project. To be noted that the eclipse has installed runtime set to JDK 1.8

I also checked that none of the .classpath .impl or .project file is checked in git repository.

Solution that worked for me: I simply deleted .classpath files and did a 'maven-update project'. .classpath file was regenerated and it picked up 1.7 as compile version from pom file.


In order to update your project to the latest version of java available in your environment, follow these steps:

  1. Open your pom.xml file
  2. Switch your view to Effective POM tab
  3. Open Find Dialog (ctrl + F) to search for maven-compiler-plugin
  4. Copy the the following lines

_x000D_
_x000D_
<plugin>_x000D_
 <artifactId>maven-compiler-plugin</artifactId>_x000D_
 <version>3.1</version>
_x000D_
_x000D_
_x000D_

  1. Click on pom.xml tab to open your project pom configuration
  2. Inside your <build> ... </build> configuration section, paste the configuration copied and modify it as...

_x000D_
_x000D_
        <plugins>_x000D_
     <plugin>_x000D_
      <artifactId>maven-compiler-plugin</artifactId>_x000D_
      <version>3.1</version>_x000D_
    _x000D_
      <configuration>_x000D_
       <source>1.8</source>_x000D_
       <target>1.8</target>_x000D_
      </configuration>_x000D_
     </plugin>_x000D_
    </plugins>
_x000D_
_x000D_
_x000D_

  1. save your configuration
  2. Right Click in your project Click on [Maven -> Update Project] and Click on OK in the displayed update dialog box.

Done!


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 your properties:

Name: “maven.compiler.target” Value: “1.8”

and

Name: “maven.compiler.source” Value: “1.8”

Now do a maven update.


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)

If you are getting following type of error

maven build error

Then do the following steps-->>

  • Go to Windows. Then select Preferences, in Which select java(on the left corner).
  • In java select Installed JREs and check your JRE(if you have correctly installed jdk and defined environment variables correct then you will see the current version of the installed java here)as shown - installed jre

(I have Java 8 installed) Check the check box if it is not checked. Click apply and close.

Now Press Alt+Enter to go into project properties,or go via right clicking on project and select Properties.

In Properties select Java Build Path on left corner

Select Libraries

Check libraries

And click edit(after selecting The JRE System Library...) In edit Click and select Workspace default JRE. Then click Finish

In Order and Export Check the JRE System Library.

Then Finally Apply and close Clean the project and then build it.

Problem Solved..Cheers!!


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.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to m2eclipse

web.xml is missing and <failOnMissingWebXml> is set to true How to solve maven 2.6 resource plugin dependency? No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? An internal error occurred during: "Updating Maven Project". java.lang.NullPointerException An internal error occurred during: "Updating Maven Project". Unsupported IClasspathEntry kind=4 Maven "build path specifies execution environment J2SE-1.5", even though I changed it to 1.7 Failed to resolve version for org.apache.maven.archetypes Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved How to deal with missing src/test/java source folder in Android/Maven project? SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error