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.co
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
java -jar -Dlog4j.configuration=log4j.properties target\yourfile-v01_000_01_c002.jar
Example code
public static void main(String[] args) {
String filename = System.getProperty("log4j.configuration");
if(null==filename||filename.trim().equals("")) {
logger.info("Using default log4j configuration log4j.default.properties.");
logger.info("If you would like to change the default configuration please add following param before startup -Dlog4j.configuration=<log4jfile>");
PropertyConfigurator.configure( Main.class.getResourceAsStream("/log4j.default.properties"));
} else {
File file = new File(filename);
if(!file.exists()) System.out.println("It is not possible to load the given log4j properties file :"+file.getAbsolutePath());
else PropertyConfigurator.configure(file.getAbsolutePath());
}
}
this works:
java -jar -Dlog4j.configuration="file:d:\log4j.xml" myjar.jar
Have you tried java -Dlog4j.configuration=/path/to/log4j.xml -jar <rest-of-args>