There are times when you need to fetch a file from your local file system on the application at runtime.

In these cases, the Mule can look stubborn and confusing. For instance, some components (E.g. Transform components) allow you to navigate to the file in question and then display that file path as a relative path from the application’s root directory. No further work necessary.

Other components (E.g. Read File component) offer exactly the same IDE feature – only on these components you get a Runtime File Not Found exception.

I don’t pretend to understand why some components behave one way with regards to relative paths while others behave differently. Suffice it to say that the File component, at least, offers a Working Directory parameter and should by definition have access to the entire file system whereas Transforms should not. This accounts for the example components but I have found the Mule to be a little erratic regarding when relative paths work and when they do not.

There are a few solutions to this problem but the simplest one I have found in the latest version of Mule (v4.x) is to use Runtime properties when required.

Whisper
${mule.home}/apps/${app.name}/

… is the magic config you need to produce the full system path to your application root, no matter where it is deployed. Simply add the relative path after that:

${mule.home}/apps/${app.name}/my/relative/path/filename.txt

et voila!

You can access your application’s files at runtime.