I am developing a library (deployed as a JAR file) which I use as "Custom Code" in my install4j project. I want to use localized messages inside that library, which are preferably defined in the library itself but should be overwritable in the install4j project definition.
Here is what I tried so far:
I passed a Context
object as a parameter to the relevant function in my library and used context.getMessage("my-message-key")
to retreive the translation for the given key. Also, I added the localization file containing the key (messages_en.utf8
) into a messages
folder in the packed JAR of the library.
Then I added that JAR to the "Custom Code" section in install4j.
In the end, this resulted in a MissingResourceException
:
java.util.MissingResourceException: Can't find resource for bundle com.install4j.runtime.util.FileResourceBundle, key my-message-key
When I add the very same JAR file as an "extension" to the extensions
dir inside the installation directory of install4j, the message key gets picked up correctly and the code runs properly without any exceptions.
However, following this approach, I'd have to add the JAR to every install4j installation within our team and also adapt installations on build servers - and redo that on each update of the library.
Therefore, I would prefer a solution where I can use it as "Custom Code". What is wrong with my approach?
As of 11.0.1, this is not supported by the i18n system in install4j, but you're right, it should just work like that.
Please contact me at support@ej-technologies.com and I will send you a build where you can try this out.