I am trying to run a jar with the log4j.xml file on the file system outside the jar like so:
java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=log4j.xml argToJar1 argToJar2
I have also tried:
java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=/opt/companyName/pathToJar/log4j.xml argToJar1 argToJar2
The log4j.xml is file is in the same directory as the jar (/opt/companyName/pathToJar/), yet I still get the standard warning message:
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
Is it possible to have the config file outside the jar, or do I have to package it with the jar?
TIA
you can define a default properties file in the jar. if no custom properties is defined you can use this default file.if a custom property is defined you can override the default property.
myjar.jar file contains log4j.default.configuration
you can run your program with this parameters to start your application
Example code
java -cp "path/to/your/log4jxml:path/to/yourjar.jar" your.package.MainClass
The log4j.xml in directory "path/to/your/log4jxml" will overwrite the log4j.xml file in "path/to/yourjar.jar".
Please refer to Setting multiple jars in java classpath.
Have you tried
java -Dlog4j.configuration=/path/to/log4j.xml -jar <rest-of-args>
I had problems using log4j with Sun's JDK and automatic configuration.
You can use this:
before using Logger.
"-jar" only uses the classpath inside the executable jar, and -cp is ignored. Adding "." to the classpath in the executable jar should allow log4j.xml to be fount.
The simplest path configuration for ``log4j2
is using the
static blocksetting
log4j.configurationFile`:Then the structure could be as:
When you run your jar, it will look outside the jar for the xml file.