How to set default Maven's Java in Eclipse?
14,443
Solution 1
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>
Solution 2
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
Solution 3
You will have to manually update the pom.xml with the following plugin because 1.5 is the default.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<classpathContainers>
<classpathContainer>
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6
</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
Refrences:
Comments
-
Suzan Cioc almost 2 years
If I create new
Maven
project inEclipse
and base it on quickstart archetype, it appears withJ2SE-1.5
inJava Build Path
window and 1.5 inJava 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?
-
khmarbaise over 10 yearsThe maven-compiler-plugin has the version 3.1 in the meantime.
-
Nicolas over 10 yearsMy mistake ;) ... Fixed!
-
khmarbaise over 10 yearsOnly the configuration part is necessary.
-
khmarbaise over 10 yearsOnly the configuration of the maven-compiler-plugin is needed. Apart from that it will set the launcher within Eclipse but not the compiler which is used by maven or to be more accurate which compatibility is used of the installed jdk.
-
Jules almost 10 yearsMaven newbie here: I have put this in my pom.xml file, and chosen "update project" from the maven menu when I right click on the project, but nothing has changed. Is there something else I have to do to get eclipse to update the java version it's using for my project?
-
NikolaDjokic over 8 yearsMaven->Update Project was necessary for me.