简体   繁体   English

如何在Eclipse中设置默认的Maven Java?

[英]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. 如果我在Eclipse创建新的Maven项目并将其基于quickstart原型,则它将在Java Build Path窗口中显示为J2SE-1.5 ,在Java Compiler / JDK Compliance窗口中显示J2SE-1.5

So, I usually have to change this to other Java manually. 所以,我通常必须手动将其更改为其他Java。

Where are these default setting come from? 这些默认设置来自哪里?

How to change to 1.6 or 1.7? 如何更改为1.6或1.7?

The m2eclipse plugin uses the settings from the POM. m2eclipse插件使用POM中的设置。 So you need to add this to your POM: 所以你需要将它添加到你的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>

You should add plugin in your pom.xml like below : 您应该在pom.xml中添加插件,如下所示:

 <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 然后您可以看到您的项目标记有错误。在这种情况下,右键单击您的项目目录 - > Maven-> Update Project选项将起作用

You will have to manually update the pom.xml with the following plugin because 1.5 is the default. 您必须使用以下插件手动更新pom.xml ,因为1.5是默认值。

<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: Refrences:

  1. Eclipse JRE System Library [J2SE-1.5] Eclipse JRE系统库[J2SE-1.5]

  2. Eclipse + Maven: force Execution Environment "JavaSE-1.6" instead of fixed JDK Eclipse + Maven:强制执行环境“JavaSE-1.6”而不是固定JDK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM