Frequently Asked Questions

The Properties Constants Maven Plugin

  1. Is creating constants for properties key a good idea at all?
  2. How big can a properties file be to work with the plugin?
  3. How can I use a centralized custom template for all of my projects?
  4. Does the properties-constants-maven-plugin support XML properties?
  5. Which file extensions are required?

Java Properties and ResourceBundles

  1. Why are some fancy chars from my properties not loaded correctly?

The Properties Constants Maven Plugin

Is creating constants for properties key a good idea at all?

Yes, this helps the developers to check at compile time whether the properties key is valid or not (assuming the constants are used with the right properties file).

A common concern is about big properties files, e.g. for I18N they might contain hundreds or more entries. The classes for this kind of properties files will be big (or even huge). But that doesn't matter, as the Java compiler embeds the constant values into the classes using them. The constant class itself is not loaded at runtime.

So, if the constants class is huge, it is a compile-time problem, not a runtime one.

[top]


How big can a properties file be to work with the plugin?

If using the default templates "keys", the maximum number of entries in a properties file is 21838. This would result in a Java class with 21839 String constants, as an additional constant for the properties file name is created.

This is the maximum number of String constants a class can have, assuming all constant values are different and the class has only the default constructor and no other method.

To understand this odd number, you might want to read up on the "constant pool" of the Java class file.

[top]


How can I use a centralized custom template for all of my projects?

Do it with a Maven dependency.

Create a jar that only contains your Freemarker template and deploy it to your local Maven repository.

Then configure the plugin similar to this:

<plugin>
  <groupId>de.r3s6.maven</groupId>
  <artifactId>properties-constants-maven-plugin</artifactId>
  <version>${properties-constants-maven-plugin.version}</version>
  <configuration>
    <basePackage>com.example.constants</basePackage>
    <template>my-custom-template.ftl</template>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>com.example.constants</groupId>
      <artifactId>prop-const-template</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</plugin>

[top]


Does the properties-constants-maven-plugin support XML properties?

Yes, if the file name extension contains xml (case insensitive), the file is read as XML properties.

Note that the content must comply to the simple Properties DTD.

[top]


Which file extensions are required?

The plugin only cares whether the file extension contains xml or not. Files witch extension contain xml (case insensitive) are read as XML. All other extensions are handled like *.properties.

[top]

Java Properties and ResourceBundles

Why are some fancy chars from my properties not loaded correctly?

The defined character encoding for properties files is ISO-8859-1 (sometime called "latin1"). Every character outside of this character set has to be encode using the \uXXXX representation.

E.g.the simple smiley ☺ can be added with \u263A.

Depending on your use case, a XML properties file might be better. See above.

Beginning with Java9 the character set for ResourceBundles can be UTF-8. See the javadoc of java.util.PropertyResourceBundle.

[top]