I need a Ant task that exports some class constants to a text file. Is it possibile or may I write a main method of that class and call it from Ant?
Asked
Active
Viewed 349 times
1 Answers
1
As already answered in a few question here (for e.g. Ant loadproperties failed (bcel error?) ) you can read class constants with the given snippet. To run this you would need the apache bcel library (http://commons.apache.org/proper/commons-bcel/]1) in the ant classpath. The 'echoproperties' will print your properties to console first. If you find your vars in there you could try to echo the needed ones to a file (echo task can do this). For me this works only till java 7 not in java 8. I might be need a becel update but even with version 6 snapshot i had problems in java 8 classes.
<target name="printVars">
<loadproperties encoding="iso-8859-1" srcfile="MyClass.class">
<filterchain>
<classconstants/>
</filterchain>
</loadproperties>
<echoproperties/>
</target>
-
it works also with java 8 - but i found out that it works only for real constant values like static String test = "myValue" - in java 7 it was also possible to concatenate static values and they where also found (like static String version = PRODUCT_NAME + "_" + SHORT_VERSION; ) – sati May 28 '14 at 13:40