Property substitution issue


I have a property SHIP_DIR defined as below: (Normally, this property would be read from a properties file).

<property name="SHIP_DIR" value="C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship" />

I use it in a pack element as follows

<pack name="Docs" required="no">
<description>The documentation</description>
<fileset dir="$SHIP_DIR"
includes="documentation/" />

I get the following error

-> Fatal error :
install.xml:130: C:\cygwin64\home\Andy\IzPack\KMPtrial\.\C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship not found.
com.izforge.izpack.api.exception.CompilerException: install.xml:130: C:\cygwin64\home\Andy\IzPack\KMPtrial\.\C:\konaware\kilauea_2.1\kmp\build\BUILD_DBG\ship not found.

Notice the "\" before the C: in the error message.

If I replace the $SHIP_DIR in the <pack> element with the value of the property SHIP_DIR, there is no error.

I now understand what is happening. I accidentally set the base directory to something other than "." and the resulting path that I got for the fileset dir above was concatenation of the absolute path of the base directory and the substituted value of $SHIP_DIR.

Here's what happens. In the following code:

That line for the "not exists" case looks like it should read something like the following You have no idea what the path in base_dir looks like if it contains variables!

baseDir = FileUtil.getAbsolutePath(variableSubstitutor.substitute(dir_attr), baseDir.getAbsolutePath());

In fact, why isn't variable substitution simply done at the outset? That's got to be faster a simpler than making a file system query and finding out it doesn't exist!

Here's what happens in the case above. The line

computes a basedir via FileUtil which constructs a File object out of the string "$SHIP_DIR" and tests if it is absolute.

"$SHIP_DIR" is not absolute, so FileUtil returns a File object constructed out of the basedir ('.") and the aforementioned File object.

Then basedir is tested for existence, which fails. So an attempt is made to construct a File object with this line.

baseDir = new File(variableSubstitutor.substitute(baseDir.getAbsolutePath()));

but getting the string on which to do the substitution from basedir which is not a valid File does not get back the original string. It has the base dir prepended! You need to start over with the original string as follows:

baseDir = FileUtil.getAbsolutePath(variableSubstitutor.substitute(dir_attr), baseDir.getAbsolutePath());

This error also exists for the "src" attribute




René Krell
March 26, 2018, 10:02 AM

Thanks for contributing. The fix will appear in the next release.

Adrien Lesur
January 16, 2018, 2:37 PM

Thank you for your very detailed post.
A PR based on it has been created.

Your pinned fields
Click on the next to a field label to start pinning.


Adrien Lesur


Andrew Hall