Link to the log4j configuration file in the executable JAR

I am creating an executable JAR that uses a pair of XML configuration files, one for the application and one for log4j. To reference the application configuration file, I do the following:

InputStream config = Util.class.getResourceAsStream("/config/config.xml"); 

This works fine for my application, but the problem is that I cannot configure log4j like that. Here is the code that configures log4j:

 DOMConfigurator.configure("/config/log4j.xml"); 

This will not work because the XML file will be stored in the JAR package. How to configure log4j to use an XML file or properties in a JAR?

+3
source share
2 answers

You can use the URL version of the DOMConfigurator.configure method. The resource must be available in / config / log 4j.xml.

 DOMConfigurator.configure(Util.class.getResource("/config/log4j.xml") 
+4
source

You can try

 DOMConfigurator.configure(Util.class.getResource("/config/log4j.xml")); 
+2
source

All Articles