How to set default Maven's Java in Eclipse?

纵饮孤独 提交于 2019-12-22 04:08:02

问题


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?


回答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>



回答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




回答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:

  1. Eclipse JRE System Library [J2SE-1.5]

  2. Eclipse + Maven: force Execution Environment "JavaSE-1.6" instead of fixed JDK



来源:https://stackoverflow.com/questions/19096608/how-to-set-default-mavens-java-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!