---
title: "Maven  Properties"
author: "dikar"
date: "2009-12-21T15:51:18Z"
tags: []
categories: ["编程语言"]
slug: "maven-properties"
draft: false
lastmod: "2009-12-21T15:52:04Z"
id: 552902
url: "https://dikar.iteye.com/blog/552902"
---

maven中有很多 可用的属性，查找了半天终于查到了 ，故在此记录下。

 

属性列表源自http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide

 

 

 

### []()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.

### []()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.` `outputD` `irectory` `}` 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.

```
<project>
...
  <properties>
     <my.filter.value>hello</my.filter.value>
  </properties>
...
</project>
```

- `${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 an [org.apache.maven.project.MavenProject](http://maven.apache.org/ref/2.0.4/maven-project/apidocs/org/apache/maven/project/MavenProject.html) 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 to `getProject().getBuild().getDirectory()` .