maven更新后Java版本自动改为java 1.5 [英] Java version automatically change to java 1.5 after maven update

查看:32
本文介绍了maven更新后Java版本自动改为java 1.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Eclipse 作为 IDE.当我右键单击该项目然后单击 maven 时,将我的 java 版本更改为 1.5.这是我到目前为止所做的,我按照此处列出的所有步骤操作

http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/

  1. 我将Java 构建路径"更改为工作区默认 jre 1.8.0_25"
  2. 然后将java编译器"更改为 1.8
  3. 然后更改project facets">java>1.8
  4. 将 pom.xml java 版本更改为 1.8

 <插件><插件><groupId>org.eclipse.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>9.1.3.v20140225</version></插件><插件><groupId>org.apache.maven.plugin</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><配置><来源>1.8</来源><目标>1.8</目标></配置></插件></插件></build>

毕竟当我点击Maven 更新"时,我的 Java 版本会自动更改为 1.5.同样在上述步骤中,前两步的版本也自动更改为 1.5.我该如何解决这个问题?

打开您的 pom.xml 文件并在其上添加以下几行:

<maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></属性>

其中 1.8 是您当前 JDK/JRE 的 Java 版本.另一种方法是添加一个 maven-compile-plugin 作为

<插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.2</version><!-- 或任何当前版本--><配置><来源>1.8</来源><目标>1.8</目标></配置></插件></插件></build>

编辑

如果您正在寻找一种方法使其适用于 Java 9+ 版本,请查看 @JDelorean's回答在这里,别忘了给他点赞:)>

I am using eclipse as IDE. When I right click on the project and then click maven update my java version change to 1.5. Here is what I did so far, I followed all the steps listed here

http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/

  1. I changed "Java build path" to "workspace default jre 1.8.0_25"
  2. Then changed "java compiler" to 1.8
  3. Then changed "project facets">java>1.8
  4. Changed pom.xml java version to 1.8

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.1.3.v20140225</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

After all this when I click on "Maven update" my java version change to 1.5 automatically. Also in above steps, first two step's version also change to 1.5 automatically. How can I fix this?

解决方案

Open your pom.xml file and add the following lines on it:

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Where 1.8 is the java version of your current JDK/JRE. Another way of doing this is adding a <build> with the maven-compile-plugin as

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version> <!-- or whatever current version -->
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins>
</build>

EDIT

If you are looking for a way to make it work with Java versions 9+ please take a look at @JDelorean's answer down here and don't forget to give him an upvote as well :)

这篇关于maven更新后Java版本自动改为java 1.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆