I need some advices from you today.
I am working on a project which uses a huge constants holding class.
There are lots of
public static final String CONST_NAME = "const_value";
I am getting those using MyConstClass.CONST_NAME
but now I need to externalise them in order to configure the project.
So I thought of 2 ways of doing this :
- Configuring the project through multiple MyConstants.java
I would compile one of them with the rest of my java classes.
Since those are constants it will ensure compile time safety.
- Adding a .properties file
This file would set every constants I need in the code.
I would get them with something like MyConstants.get("CONST_NAME");
Far more elegant than having multiple java classes (right?) that you would / would'nt compile with the rest of the project.
But it doesn't ensure a compile time safety which is quite required to avoid some man made mistakes.
So here is my questions :
- Is it possible to check AT COMPILE TIME that all the properties I get with
MyConstants.get("CONST_NAME");
are existing in my .properties file? - Is there a better way?
PS:
I found topics like this one and this other one but I don't think that's the way to do it.