简体   繁体   English

Eclipse 使用与 java 构建路径中提供的 JRE 不同的 JRE 构建项目

[英]Eclipse building the project with a different JRE than the one provided in java build path

I am new to eclipse and trying to run a spring application with a number of modules.我是 eclipse 的新手,并尝试运行带有多个模块的 spring 应用程序。 I am setting the build path and compiler to use jdk 1.8 but when I run maven install it is building the project using JRE 1.5 for all the modules somehow.我正在将构建路径和编译器设置为使用 jdk 1.8,但是当我运行 maven install 时,它正在以某种方式为所有模块使用 JRE 1.5 构建项目。 I checked the pom.xml but no where the compiler version was defined.我检查了 pom.xml 但没有定义编译器版本。 I wanted to know if anyone can help me with the reasons why I may be facing this issue.我想知道是否有人可以帮助我解决我可能面临这个问题的原因。

Right click on the project.右键单击项目。 Go to "Properties". Go 到“属性”。 Select "Java" in the left pane, and choose "Installer JRE". Select 在左侧窗格中选择“Java”,然后选择“Installer JRE”。 See which JRE is pointed to.查看指向哪个 JRE。 If you want, change it to your desired jre.如果需要,请将其更改为所需的 jre。 If that is in correct configuration, then choose "Compiler " option under "Java" and check the Java version used.如果配置正确,则选择“Java”下的“编译器”选项并检查使用的 Java 版本。 If it points to 1.5, override it to 1.8 and check again.如果它指向 1.5,将其覆盖为 1.8 并再次检查。

So In anyone of these places, java might be pointed to 1.5.所以在这些地方的任何一个地方,java 都可能指向 1.5。

If all the above are good, check the java path in environment variables and check if it points to 1.5 or 1.8如果以上都正常,检查环境变量中的java路径,看是指向1.5还是1.8

If you want to make sure that newly created projects in Eclipse use another default java version than Java 1.5, you can change the configuration in the maven-compiler-plugin.如果要确保 Eclipse 中新创建的项目使用另一个默认的 java 版本而不是 Java 1.5,您可以在 1.5 中更改配置。

Go to the folder.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1 Open maven-compiler-plugin-3.1.jar with a zip program. Go 到文件夹 .m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1 打开 maven-compiler-plugin-3.1.jar 与 ZADCDBD79A8D840275.1 程序Go to META-INF/maven and open the plugin.xml In the following lines: Go 到 META-INF/maven 并打开 plugin.xml 在以下几行:

${maven.compiler.source} ${maven.compiler.target} ${maven.compiler.source} ${maven.compiler.target}

change the default-value to 1.7 or 1.8 or whatever you like.将默认值更改为 1.7 或 1.8 或任何您喜欢的值。

Save the file and make sure it is written back to the zip file.保存文件并确保将其写回 zip 文件。 From now on, all new Maven projects use the java version you specified.从现在开始,所有新的 Maven 项目都使用您指定的 java 版本。

Information is from the following blog post: https://sandocean.wordpress.com/2019/03/22/directly-generating-maven-projects-in-eclipse-with-java-version-newer-than-1-5/信息来自以下博客文章: https://sandocean.wordpress.com/2019/03/22/directly-generating-maven-projects-in-eclipse-with-java-version-newer-than-1-5/

More Link: Why Maven project is tied to J2SE-1.5 by default?更多链接: 为什么Maven项目默认绑定到J2SE-1.5?

What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't? What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?

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

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