8 December 2008
When it comes to distributing Java applications to end users there are a few different routes one can take.
One common approach for me is to use JarJar to create a single jar file from the application’s jar(s) and its dependencies.
I recently ran into a familiar log4j warning message when trying to run an application from a single combined jar.
log4j:WARN No appenders could be found for logger (org.apache.commons.configuration.ConfigurationUtils). log4j:WARN Please initialize the log4j system properly.
I was confused by this because I was certain that a log4j.properties file was bundled in the application jar. After opening the jar file as a zip file, I quickly realized what the problem was.
As you can see above, the problem is that two other jars also bundle a log4j.properties at the same base path. As we all know, only one file with the same name can exist at the same path. So, when the JRE loads the combined jar, only one log4j.properties file is recognized.
This sort of issue can come up in many different situations and something you should keep in mind when using JarJar. Another example from the same jar is shown below.
The quick and dirty solution was to manually combine the three log4j.properties files into one and replace the three log4j.properties files in the archive with the single combined properties file. This is hardly an ideal solution and something I will eventually need to revisit.
No related posts.