天天看點

轉 maven常用内置變量

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!

${basedir} represents the directory containing pom.xml

${version} equivalent to ${project.version} or ${pom.version}

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

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 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>

all java system properties defined by the jvm.

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

how can parent project variables be accessed?

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

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

the pattern ${somex.somey.somez} can simply sometimes mean getsomex().getsomey().getsomez(). thus, properties such as ${project.build.directory} is translated togetproject().getbuild().getdirectory().