gpt4 book ai didi

spring-boot - pom.xml maven 中的属性标签是什么意思?

转载 作者:行者123 更新时间:2023-12-04 13:10:37 26 4
gpt4 key购买 nike

我在 spring boot 工作,我看到了 属性(property)标签在 pom.xml 文件,但我不明白它是什么意思,我们可以在这个标签中做什么。
属性(property)标记例如

   <properties>
<java.version>1.8</java.version>
</properties>
什么 属性(property)标签是什么意思?
我还可以在 中添加什么属性(property)标签 ?

最佳答案

属性标签是什么意思?
来自官方 Maven 文档:

Properties are the last required piece to understand POM basics. Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example:


在您的情况下,您已将属性定义为 java 版本。
现在这个属性( java.version )可以稍后在 maven pom 文件中重用。
来自官方 Maven 文档:

They come in five different styles:

  • env.X: Prefixing a variable with "env." will return the shell's environment variable. For example, ${env.PATH} contains the PATHenvironment variable. Note: While environment variables themselves arecase-insensitive on Windows, lookup of properties is case-sensitive.In other words, while the Windows shell returns the same value for%PATH% and %Path%, Maven distinguishes between ${env.PATH} and${env.Path}. The names of environment variables are normalized to allupper-case for the sake of reliability.

  • project.x: A dot (.) notated path in the POM will contain the corresponding element's value. For example:1.0 is accessible via${project.version}.

  • settings.x: A dot (.) notated path in the settings.xml will contain the corresponding element's value. For example:false is accessible via${settings.offline}.

  • Java System Properties: All properties accessible via java.lang.System.getProperties() a-re available as POM properties,such as ${java.home}.

  • x: Set within a element in the POM. The value of value may be used as${someVar}.


我还可以在属性标签中添加什么?
您可以在 maven pom 文件中添加稍后需要重用的所有变量。
例如下面的 POM 片段重用了 jackson.version 4 次。
<properties>
<jackson.version>2.10.2</jackson.version>
<dropwizard.version>2.0.1</dropwizard.version>
<websocket.version>1.4.0</websocket.version>
<apachehttp.version>4.5.10</apachehttp.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apachehttp.version}</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>${websocket.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependencies>
引用 :
Maven Pom Properties

关于spring-boot - pom.xml maven 中的属性标签是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65696058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com