Maven project properties are not automatically added to Java system properties. There are many options for this. For this specific need, you can define the System property for the maven-surefire-plugin (those that run the tests), and then use the System.getProperty method.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.10</version> <configuration> <systemProperties> <property> <name>projectArtifactId</name> <value>${project.artifactId}</value> </property> </systemProperties> </configuration> </plugin>
Another way to achieve Maven properties for JUnit tests is probably by filtering resources for the source source files.
PS. Reading Maven configurations at runtime, even in tests, is pretty dirty IMHO. :)
source share