pom.xml maven 中的属性标记是什么意思?
What does properties tag mean in pom.xml maven?
我在 spring 引导下工作,我在 pom.xml 文件中看到 properties 标记,但我没有不明白这是什么意思,我们可以在这个标签里做什么。
属性 标签例如
<properties>
<java.version>1.8</java.version>
</properties>
properties 标签是什么意思?
我还可以在 properties 标签中添加什么?
属性标签是什么意思?
来自官方 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 PATH
environment variable. Note: While environment variables themselves are
case-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 all
upper-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>
参考资料:
我在 spring 引导下工作,我在 pom.xml 文件中看到 properties 标记,但我没有不明白这是什么意思,我们可以在这个标签里做什么。
属性 标签例如
<properties>
<java.version>1.8</java.version>
</properties>
properties 标签是什么意思?
我还可以在 properties 标签中添加什么?
属性标签是什么意思?
来自官方 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 PATH environment variable. Note: While environment variables themselves are case-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 all upper-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>
参考资料: