Usage
Project Directories
The following diagram shows the default layout used by the properties-constants-maven-plugin
Project Root
|
+- src/main/resources # directory scanned for properties files
|
+- target
|
+- generated-sources/prop-constants
# directory to store generated java files
Simple properties
Reads *.properties
files from src/main/resources
and generates Java classes
in the package de.r3s6.constants
.
The default template “keys” is used.
<build>
<plugins>
<plugin>
<groupId>de.r3s6.maven</groupId>
<artifactId>properties-constants-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<basePackage>de.r3s6.constants</basePackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
To create constants that contains property values, use the template “values”.
<build>
<plugins>
<plugin>
<groupId>de.r3s6.maven</groupId>
<artifactId>properties-constants-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<basePackage>de.r3s6.constants</basePackage>
<template>values</template>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I18N - ResourceBundle
Reads ResourceBundle properties files from src/main/resources/i18n
. It ignores
files with a locale marker (like messages_en.properties
). Instead of the constant
holding the properties file name, a constant holding the bundle name is added to
the generated class.
<build>
<plugins>
<plugin>
<groupId>de.r3s6.maven</groupId>
<artifactId>properties-constants-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<basePackage>de.r3s6.constants.i18n</basePackage>
<includes>
<include>i18n/*.properties</include>
</includes>
<excludes>
<exclude>i18n/*_??.properties</exclude>
</excludes>
<templateOptions>
<genPropertiesFilenameConstant>false</genPropertiesFilenameConstant>
<genBundleNameConstant>true</genBundleNameConstant>
</templateOptions>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>