- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将 Java 11 指定为 Spring(或 Spring Boot)pom.xml 文件中使用的版本的正确方法是什么?
即,我需要在 pom 的 java.version
属性中放入什么值?
对于 Java 8,我们使用 1.8
,就像 the documentation shows ,对于 Java 9 来说是 1.9
。
我不确定 Java 11 是否是 1.11
(尽管看起来不太可能),并且在使用 时我看到它被指定为
,但是我没有使用编译器插件。11
maven-compiler-plugin
例如
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
我四处搜索却找不到答案,因为我读过的几乎所有文档以及与 Java 版本相关的博客文章都只显示版本 8 或 9。
那么我应该使用什么? 1.11
还是只是 11
?
我尝试了两者,我的网络服务器似乎正确启动并正确编译(IntelliJ 显示信息:javac 11.0.2 用于编译 java 源
),但是我并不完全相信更改java.version
值可以做任何事情,因为我可以将其设置为例如100
一切正常。
我能找到的唯一相关问题是:Minimum Spring version compatible with Java 11 , Spring Boot fails due to a Hibernate error after migrating to JDK 11和 Spring 4.3.x with OpenJDK 11 ,但它们并没有真正阐明任何问题。
最佳答案
简短回答:
正确的方法是使用 <java.version>
中的以下值对于不同的 Java 版本:
所以对于 Java 11 来说,它应该是:
<properties>
<java.version>11</java.version>
</properties>
However I'm not sure if Java 11 would be "1.11" (seems unlikely), andI've seen it specified as just "11" when using maven-compiler-plugin,however I'm not using the compiler plugin.
其实最后还是用maven-compiler-plugin
编译。 springboot只是配置了一个<java.version>
属性,通过更改此值,您将隐式更改 maven-compiler-plugin
的<source/>
和<target/>
与 <java.version>
中指定的值相同:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source> <!-- same as <java.version> -->
<target>11</target> <!-- same as <java.version> -->
</configuration>
</plugin>
<小时/>
详细答案:
似乎您需要细节来说服您。
这是因为每个Spring Boot项目都会扩展父pom spring-boot-starter-parent
其中defines <java.version>
如下:
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
来自 maven-compiler-plugin docs , maven.compiler.source
和maven.compiler.target
是user property对于<source>
和<target>
配置参数。由于用户属性的行为,将这两个属性设置为 11
意味着设置以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source> <!-- maven.compiler.source -->
<target>11</target> <!-- maven.compiler.target -->
</configuration>
</plugin>
来自maven-compiler-plugin
docs再次,<source>
和<target>
是-source
和-target
Java 编译器的参数 ( javac
)。然后,从 javac文档中,我们可以看到这两个参数允许具有以下值:
- 1.6 : No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors instead ofwarnings as was done in earlier releases of Java Platform, Standard Edition.
- 6 : Synonym for 1.6.
- 1.7 : The compiler accepts code with features introduced in Java SE 7.
- 7 : Synonym for 1.7.
- 1.8 : The compiler accepts code with features introduced in Java SE 8.
- 8 : Synonym for 1.8.
- 9 : The compiler accepts code with features introduced in Java SE 9.
- 10 : The compiler accepts code with features introduced in Java SE 10.
- 11 : The compiler accepts code with features introduced in Java SE 11.
- 12 : The compiler accepts code with features introduced in Java SE 12.
因此,<java.version>
应设置为11
适用于 Java 11。
关于java - 如何在Spring/Spring Boot pom.xml中指定Java版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54467287/
正如标题中所问,我有两个如下结构的 XML 文件 A.xml //here I want to include B.xml
我有一个 xml 文件。根据我的要求,我需要更新空标签,例如我需要更改 to .是否可以像那样更改标签.. 谢谢... 最佳答案 var xmlString=" "; var properStri
我有这样简单的 XML: Song Playing 09:41:18 Frederic Delius Violin Son
在我的工作中,我们有自己的 XML 类来构建 DOM,但我不确定应该如何处理连续的空格? 例如 Hello World 当它被读入 DOM 时,文本节点应该包含 Hello 和 World
我有以下 2 个 xml 文件,我必须通过比较 wd:Task_Name_ID 和 TaskID 的 XML 文件 2。 例如,Main XML File-1 wd:Task_Name_ID 具有以下
我在 Rails 应用程序中有一个 XML View ,需要从另一个文件插入 XML 以进行测试。 我想说“构建器,只需盲目地填充这个字符串,因为它已经是 xml”,但我在文档中看不到这样做的任何内容
我正在重建一些 XML 提要,因此我正在研究何时使用元素以及何时使用带有 XML 的属性。 一些网站说“数据在元素中,元数据在属性中。” 那么,两者有什么区别呢? 让我们以 W3Schools 为例:
在同一个文档中有两个 XML 声明是否是格式正确的 XML? hello 我相信不是,但是我找不到支持我的消息来源。 来自 Extensible Markup Language
我需要在包装器 XML 文档中嵌入任意(语法上有效的)XML 文档。嵌入式文档被视为纯文本,在解析包装文档时不需要可解析。 我知道“CDATA trick”,但如果内部 XML 文档本身包含 CDAT
XML 解析器和 XML 处理器是两个不同的东西吗?他们是两个不同的工作吗? 最佳答案 XML 解析器和 XML 处理器是一样的。它不适用于其他语言。 XML 是通用数据标记语言。解析 XML 文件已
我使用这个 perl 代码从一个文件中读取 XML,然后写入另一个文件(我的完整脚本有添加属性的代码): #!usr/bin/perl -w use strict; use XML::DOM; use
我正在编写一个我了解有限的历史脚本。 对象 A 的类型为 system.xml.xmlelement,我需要将其转换为类型 system.xml.xmldocument 以与对象 B 进行比较(类型
我有以下两个 XML 文件: 文件1 101 102 103 501 502 503
我有以下两个 XML 文件: 文件1 101 102 103 501 502 503
我有一个案例,其中一个 xml 作为输入,另一个 xml 作为输出:我可以选择使用 XSL 和通过 JAXB 进行 Unmarshalling 编码。性能方面,有什么真正的区别吗? 最佳答案 首先,程
我有包含 XML 的 XML,我想使用 JAXB 解析它 qwqweqwezxcasdasd eee 解析器 public static NotificationRequest parse(Strin
xml: mario de2f15d014d40b93578d255e6221fd60 Mario F 23 maria maria
尝试更新 xml 文件数组时出现以下错误。 代码片段: File dir = new File("c:\\XML"); File[] files = dir.listFiles(new Filenam
我怎样才能完成这样的事情: PS /home/nicholas/powershell> PS /home/nicholas/powershell> $date=(Get-Date | ConvertT
我在从 xml 文件中删除节点时遇到一些困难。我发现很多其他人通过各种方式在 powershell 中执行此操作的示例,下面的代码似乎与我见过的许多其他示例相同,但我没有得到所需的行为。 我的目标是将
我是一名优秀的程序员,十分优秀!