On Jun 20, 2005, at 7:44 PM, Eric Pieters wrote:

Hi,

Is there somebody out there which can provide an example of how I can load a XML config file from a jar? The idea is to add i.e. appl.xml to a jar and call DOMConfigurator.configure("appl.xml") within the application.

I would like to hide part of the configuration from the end-users to avoid that they make changes to parts of the configuration.

Other ideas are welcome as well.
Another path I walked was to do the 'hidden' part within the code, but I could find a way to add the rendering info into th repository. So, ideas or hints on how to do that are welcome as well.

Thanks


I'll repeat the reply that I sent when you asked this on log4cxx-user:

DOMConfigurator.configure(String) gives no indication that its parameter is treated as anything other than plain filename. So expecting it to be used in a search within a jar file is unwarranted.

I think what you you would likely end up needing to do is to obtain an URL for the resource using org.MyApp.MyClass.class.getResource("/ conf/MyApp.xml") and then calling DOMConfigurator(URL).

Did you have a problem with this approach? Your code should look something like (omitting exception handling code and not checked for syntax):

String pathInJar = "/appl.xml";
URL configURL = getClass().getResource(pathInJar);
if (configURL != null) {
    DOMConfigurator.configure(configURL);
}


FYI: The URL returned from getResource() would look something like "jar:file:///pathtojar/jarfile.jar#/appl.xml".








---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to