A
Alex Hunsley
I'm using log4j (via Jakarta common-logging but that part is irrelevant).
Things work fine with the configuration file, log4j.properties, in the jar file
I'm making that contains the code. However, I'd like the log4j.properties to be
in the same folder as the jar file, not inside the jar, as this makes it much
more accessible (read: editable). Now since log4j looks at a system setting for
the location of the jar file I can do this:
System.setProperty("log4j.configuration",
jarFileLocation); // jarFileLocation is a String
I find out the value of jarFileLocation by doing this in the code:
java.net.URL classURL =
new TestApp().getClass().getResource(className);
.... and then by doing hacky ugly things to the resulting URL to get a string.
This works, but is not very satisfactory to me; seems too hacky and prone to
break somehow.
So: is there any better way to get log4j to read its config file from the same
dir as the jar containing the currently running code? Or is this hack the best
there is?
thanks
alex
Things work fine with the configuration file, log4j.properties, in the jar file
I'm making that contains the code. However, I'd like the log4j.properties to be
in the same folder as the jar file, not inside the jar, as this makes it much
more accessible (read: editable). Now since log4j looks at a system setting for
the location of the jar file I can do this:
System.setProperty("log4j.configuration",
jarFileLocation); // jarFileLocation is a String
I find out the value of jarFileLocation by doing this in the code:
java.net.URL classURL =
new TestApp().getClass().getResource(className);
.... and then by doing hacky ugly things to the resulting URL to get a string.
This works, but is not very satisfactory to me; seems too hacky and prone to
break somehow.
So: is there any better way to get log4j to read its config file from the same
dir as the jar containing the currently running code? Or is this hack the best
there is?
thanks
alex