Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default Maven's Java in Eclipse?

If I create new Maven project in Eclipse and base it on quickstart archetype, it appears with J2SE-1.5 in Java Build Path window and 1.5 in Java Compiler / JDK Compliance window.

So, I usually have to change this to other Java manually.

Where are these default setting come from?

How to change to 1.6 or 1.7?

like image 608
Suzan Cioc Avatar asked Sep 30 '13 14:09

Suzan Cioc


People also ask

Where is Maven path in Eclipse?

Open Eclipse and navigate to Window->Preferences . Then go to Java->Build Path->Classpath Variables within the preferences window. In the Classpath Variables pane, add a variable named "M2_REPO" with a path pointing to the directory of your local Maven repository.

Do we need to install Maven separately for Eclipse?

NOTES:Eclipse Kepler (4.3) and newer versions already have Maven integration so you don't need to install the plug-in for this version of Eclipse.


2 Answers

You should add plugin in your pom.xml like below :

 <build>
    <pluginManagement>
      <plugins>
         <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>your version</version>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
         <configuration>
            <source>1.7</source>
            <target>1.7</target>
         </configuration>
      </plugin>
      </plugins>
    </pluginManagement>
  </build>

And then you can see your project marked with error.In this case, Right click your project directory->Maven->Update Project option will work

like image 40
justadeveloper Avatar answered Oct 07 '22 22:10

justadeveloper


The m2eclipse plugin uses the settings from the POM. So you need to add this to your POM:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>
like image 120
Nicolas Avatar answered Oct 07 '22 22:10

Nicolas