Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 586
bheussler Avatar asked Feb 11 '13 02:02

bheussler


4 Answers

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>
like image 139
javabeangrinder Avatar answered Nov 13 '22 09:11

javabeangrinder


  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.
like image 28
Brett VanderVeen Avatar answered Nov 13 '22 09:11

Brett VanderVeen


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.

like image 32
Torisuta Avatar answered Nov 13 '22 08:11

Torisuta


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.

like image 13
user3444334 Avatar answered Nov 13 '22 09:11

user3444334