Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kklisura/props-to-constants-generator
Properties file to Java constants
https://github.com/kklisura/props-to-constants-generator
constants generator java-8 properties
Last synced: 2 months ago
JSON representation
Properties file to Java constants
- Host: GitHub
- URL: https://github.com/kklisura/props-to-constants-generator
- Owner: kklisura
- License: mit
- Created: 2018-06-11T09:09:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-28T03:21:42.000Z (12 months ago)
- Last Synced: 2024-04-24T12:19:38.256Z (9 months ago)
- Topics: constants, generator, java-8, properties
- Language: Java
- Homepage:
- Size: 29.3 KB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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`:
```xmlcom.github.kklisura.java.processing
props-to-constants-generator
1.0.0
provided```
Add `PropertySourceConstants` annotation:
```java
@PropertySourceConstants(resourceName = "messages.properties", className = "Messages_")
public class Application {
public static void main(String[] args) {
// ...
}
}
```
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:
```properties
hello=123
hello.world=321
```...and the above configuration, the following constants class would be created:
```java
public final class Messages_ {
public static final String HELLO = "hello";
public static final String HELLO_WORLD = "hello.world";private Messages_() {}
}
```# License
MIT