Action for accessing java properties files

We use ANT Build scripts with Finalbuilder to build our java programs. Settings for the ant build script (build.xml) are made with different entries in the build.properties file.

Today we must read the file line by line, change the line if a key is found and write it to a new file.

It should be nice to have Actions like “Read Ini File” and “Write Ini File” to access the settings in a properties file more easyer.

The properties files are like ini files, but without sections.
Only “key = value” entries and commentlines (beginning with #) are found inside.

Michael Oehlhof

Hi Michael,

We can look into this. However, there may be ways to work around it without a dedicated action.

One way is to make a template file, say ‘build.properties.template’. Anywhere that you need a key value to be replaced, use a FinalBuilder variable name, ie

Version=%ProductVer.MajorVersion%.%ProductVer.MinorVersion%.%ProductVer.BuildVersion%
BuildOptions=%BuildOpts%

… then define and set the variables that you need (in the example above, a variable named BuildOpts and a PropertySet named ProductVer.)

Finally, use the ‘Text Replace’ action with ‘Replace FinalBuilder Variables’ to read in ‘build.properties.template’ file and write out a ‘build.properties’ file with all of the correct values set.

We use a similar approach when building some of our Inno Setup files.

Hth.

- Angus

For all the people with the same problem, here is a simple way how I resolved it.

Read the content of the file in a variable CONTENT

Write it back to the file with
[java]
%CONTENT%

Use "Read Ini File" and "Write Ini File" actions to change the properties.

Make a Text replace in the file, replace
[java]

with nothing (empty Replacement String).
Make shure you have entered new line after the search string [java], otherwise an empty line leaves at the beginning of the properties file.

A sample test project is added as attachement for those who want to copy and paste the actions.

Regards
Michael

propertiestest.fbp6 (25.697 KB)