【问题标题】:Updating the pom.xml with Eclipse使用 Eclipse 更新 pom.xml
【发布时间】:2013-08-15 17:55:58
【问题描述】:

使用带有 m2eclipse 插件的 Eclipse,如何更新 pom.xml,这样“Maven->Update Project”不会将项目配置重置回 Java 1.5? 我正在使用 Eclipse Kepler 4.3、Java 7 和 m2eclipse 插件。 我创建了一个新的 Maven 项目,勾选了“创建一个简单的项目(跳过原型选择)”,artifactId 为“test”。我收到以下警告。

描述资源路径位置类型 构建路径指定执行环境 J2SE-1.5。工作空间中没有安装与此环境严格兼容的 JRE。测试构建路径JRE系统库问题

我使用以下步骤将编译器从 1.5 更改为 1.7。 1. 在项目上,右键单击“属性”并选择“Java 构建路径”。 2. 转到“库”选项卡。 3. 删除旧的 JRE 系统库 [JavaSE-1.5]。 4. 点击“Add Library...”,选择“JRE System Library”,点击“Next>”。 5. 选中“Execution environment”单选按钮并从相邻菜单中选择“JavaSE 1.7 ...”。 6.点击“完成” 7. 点击“确定”。

警告消失。

我右键单击项目并选择“Maven->更新项目”。我点击“确定”。

警告信息返回。

我的理解是插件使用 pom.xml 来更新 Eclipse 的当前设置。如何更新 pom.xml,使“Maven->Update Project”不会将项目配置重置回 Java 1.5?

我查看了这些页面,但我认为答案已经过时。 Warning - Build path specifies execution environment J2SE-1.4 What causes a new Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't? maven does not compile in java 1.6

例如,添加……

<configuration> <source>1.7</source> <target>1.7</target> </configuration>

...在 POM 中的版本部分没有解决问题之后。

【问题讨论】:

    标签: java m2eclipse


    【解决方案1】:

    你需要使用maven编译插件。

    <build>
        <plugins>
            <!-- Tell maven to compile using Java 1.7 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

    • 我将 pom.xml 更新为如下所示。&lt;project ...&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.aglx&lt;/groupId&gt; &lt;artifactId&gt;test&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;3.1&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.7&lt;/source&gt; &lt;target&gt;1.7&lt;/target&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/project&gt;这并没有解决问题。
    • 1.您缺少插件周围的构建标签。 2. 注释是放代码sn-ps的可怕地方。
    【解决方案2】:

    您需要将 Maven 编译器插件设置为使用特定版本

    <build>
    <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>
    </build>
    

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多