转 maven常用内置变量

简介:

Intro

Because I couldn't find a clear overview of which properties are availabe in maven2 I started this page. It is a collection of things found in the offcial maven documentation and postings to the maven user mailing list.

Note: In Maven 3.0, all pom.* properties are deprecated. Use project.* instead!

Build in properties

  • ${basedir} represents the directory containing pom.xml
  • ${version} equivalent to ${project.version} or ${pom.version}

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix or using pom. as prefix. This list is just an example of some commonly used elements.

  • ${project.build.directory} results in the path to your "target" dir, this is the same as ${pom.project.build.directory}
  • ${project.build.outputDirectory} results in the path to your "target/classes" dir
  • ${project.name} or ${pom.name} refers to the name of the project.
  • ${project.version} or ${pom.version} refers to the version of the project.
  • ${project.build.finalName} refers to the final name of the file created when the built project is packaged

Local user settings

Similarly, values in the user's settings.xml can be referenced using property names with settings. prefix.

  • ${settings.localRepository} refers to the path of the user's local repository.
  • ${maven.repo.local} also works for backward compatibility with maven1 ??

Environment variables

Environment variables can be referenced using the env prefix

  • ${env.M2_HOME} returns the Maven2 installation path.
  • ${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
    <jvm>${java.home}../bin/java.exe</jvm>

Java system properties

All Java System Properties defined by the JVM.

Custom properties in the POM

User defined properties in the pom.xml.

  • ${my.filter.value} will result in hello if you inserted the above XML fragment in your pom.xml

Parent Project variables

How can parent project variables be accessed?

You can use the prefix: ${project.parent}.

A good way to determine possible variables is to have a look directly at the API. I'm currently using Maven 2.2.1, and to access the Parent you can use ${project.parent}. This will return anorg.apache.maven.project.MavenProject instance.

To access the parent version: ${parent.version}.

Reflection Properties

The pattern ${someX.someY.someZ} can simply sometimes mean getSomeX().getSomeY().getSomeZ(). Thus, properties such as ${project.build.directory} is translated togetProject().getBuild().getDirectory().

 

From:http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide


目录
相关文章
|
11月前
|
Java Maven
Maven 中的内置变量说明
Maven 中的内置变量说明
|
Java Shell Maven
Mac下使用oh-my-zsh配置Java环境变量和安装maven
想要开启Java编程之路,首先要解决的问题就是如何搭建Java开发环境,通过了解,首先要安装JDK,接下来就是maven的安装。这里我遇到的最大的坑就是我的Mac之前配置的oh-my-zsh,而在网上找的资料全都是在bash下配置的,由于一直出错,没办法,只能去了解下bash和zsh的区别。好了,这里就把配置Java开发环境遇到坑的过程贴出来,让一些跟我遇到一样问题的小伙伴们少走一些弯路。
Mac下使用oh-my-zsh配置Java环境变量和安装maven
|
Java Maven Android开发
eclipse 安装maven 同时、解决自带的maven无法读取本地架包的问题、解决:找不到符号 [ERROR] 符号: 变量
1、安装在参考别人的帖子的,直接看就行了 2、解决 找不到符号 [ERROR] 符号: 变量,解决得有点辛酸
85 0
eclipse 安装maven 同时、解决自带的maven无法读取本地架包的问题、解决:找不到符号 [ERROR]   符号:   变量
|
Java Maven
Maven变量定义
Maven变量定义
|
Java Maven
Maven内建变量
Maven内建变量
|
Java API Maven
maven变量属性(${} properties)
maven变量属性(${} properties)
711 0
|
Java Maven
maven中properties标签定义变量
maven中properties标签定义变量
170 0
|
2天前
|
Java Maven
Maven 项目测试
接下来我们要学习如何构建和测试这个项目。
16 5