项目作者: kklisura

项目描述 :
Properties file to Java constants
高级语言: Java
项目地址: git://github.com/kklisura/props-to-constants-generator.git
创建时间: 2018-06-11T09:09:49Z
项目社区:https://github.com/kklisura/props-to-constants-generator

开源协议:MIT License

下载


props-to-constants-generator

Introduction

props-to-constants-generator generates a constants class of keys in your properties file. This enables you to have compile time dependency of keys on a properties file.

Tehnically, props-to-constants-generator is an Java annotation processor that processes PropertySourceConstants annotations which contain information from which properties file you wish to generate constants and output constants class name. For every PropertySourceConstants annotation, it reads a specified properties file and outputs the class containing constants of property keys.

How to use

Add the following depencency to your pom.xml:

  1. <dependency>
  2. <groupId>com.github.kklisura.java.processing</groupId>
  3. <artifactId>props-to-constants-generator</artifactId>
  4. <version>1.0.0</version>
  5. <scope>provided</scope>
  6. </dependency>

Add PropertySourceConstants annotation:

  1. @PropertySourceConstants(resourceName = "messages.properties", className = "Messages_")
  2. public class Application {
  3. public static void main(String[] args) {
  4. // ...
  5. }
  6. }

When you compile the application like you normaly do, Messages_ class should be generated in target/generated-sources/annotations/... directory.

Example

Given the following example properties file:

  1. hello=123
  2. hello.world=321

…and the above configuration, the following constants class would be created:

  1. public final class Messages_ {
  2. public static final String HELLO = "hello";
  3. public static final String HELLO_WORLD = "hello.world";
  4. private Messages_() {}
  5. }

License

MIT