ANT task to process properties-files into static class
Hi,
I think this problem is very interesting. I have a web application that needs various configuration. I'm using a properties file that is loaded into a Properties-class.
The problem arrises when runtime exceptions are thrown (NullPointerException) by using:
String value = props.getProperty("myProp");
(In this case the entry "myProp" is not available.)
The solution would be to process the properties file and put all keys and values into a class with public static attributes:
class Props {
public static String myProp = "123";
.....
}
This processing should be done with ANT! It shall create a JAVA file before the general compilation task. This would be great and runtime exceptions concerning a lack of propertie-keys are extinguished forever.
Is there any tool for ANT that helps?
Thanks in advance.
[888 byte] By [
Rapthora] at [2007-11-26 13:54:57]

Personally, I would not like it - I can't compile even parts of my code without running Ant to build the whole thing? Second, I do not want my build tool to alter or add any source files.
IMO, you should instead simply go and check for null values before using them. I'd regard these NPEs rather as programming flaws - you already pointed out that their value may be null, so not checking is just wrong.
Lastly, maybe you can create a tool yourself - generating a code like this is highly trivial. you only have to keep in mind that development will be a PITA because an IDE with incremental compile will always fail with compilation errors as long as it doesn't create that constants class Ant's supposed to create.
Oh, and why not ask Ant-related questions in an Ant forum?
Ok, I get what you intend to say.
But don't you think compile time errors are to prefer over runtime errors?
Further on I don't need to compile ANT everytime before the general compilation. I have to run it when properties change. From then on the rest of my project will always compile fine without errors.
I'm disgussed by getting NullPointerExceptions for the reason having forgot to add a value to the properties file in development. The time to restart Tomcat after having inserted the new value into the file is lost.
However, I'll try to find an ANT forum.
Thanks