Simple java application that parses a java properties file (using apache's commons-configuration) and outputs it as program arguments
Must have maven installed
Run mvn clean package
This creates an executable jar at target/property-parser-1.0-SNAPSHOT.jar
With a test.properties
file like this:
foo=bar
hello=it's a foo ${foo} world
And once you have your executable jar you may then run something like this:
java -jar target/property-parser-1.0-SNAPSHOT.jar src/test/resources/test.properties -q
It should output something like this: -Dfoo=bar '-Dhello=it\'s a foo bar world'
The template
command takes a properties file and a template file (or takes text from stdin) and does string substitution on the input using the properties file.
The string substitution is done using Apache's StrSubstitutor.
You can run the template
command using something like this:
java -jar target/property-parser-1.4.jar template src/test/resources/test.properties src/test/resources/template.html
It will write the output to stdout, unless you specify an -o
or --out
argument like this:
java -jar target/property-parser-1.4.jar template -o /tmp/output.html src/test/resources/test.properties src/test/resources/template.html
- Added a
System.exit(0);
after running the command. Apparently not having this causes issues in some kernels. I was experiencing defunct java processes in boot2docker 1.9.1.
- Ditch commons-configuration ... didn't like how it handled the properties (i.e. first properties take precedence in some cases, and then when doing the str substitution thing it would put substitute
${foo}
with[default, bar]
instead of justbar
. So instead just use the default java properties class and use StrSubstitutor to do nested property substitutions. - Bring in commons-lang3
- Now the last properties take precedence over the first
- Added 'command' framework
- Added 'template' command. Which allows for replacing property placeholders in a file using Apache's StrSubstitutor.
- Added EscapeType.NONE
- Change default EscapeType to DOUBLE_QUOTE
- Added travis-ci build
- Move the beginning of the wrapper quotes to include the
-Dkey=
. So instead of-Dfoo='the bar'
it becomes'-Dfoo=the bar'
- Added escape type options:
- -s / --slash which escapes spaces with a back slash
- -q / --single-quote which escapes values with spaces by wrapping them in single quotes
- -d / --double-quote which escapes values with spaces by wrapping them in double quotes
- Default escape type is back slash (which is different from v1.0...single quotes)
- Initial release. Parses properties file as java
-D
options. Escapes the values with spaces by wrapping the value in single quotes.