You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Eric Pieters <er...@gmail.com> on 2005/06/21 02:44:55 UTC

Reading config.xml from jarfile

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

-- Eric.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Reading config.xml from jarfile

Posted by Eric Pieters <er...@gmail.com>.
Curt Arnold wrote:
> 
> 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:
> 
Now I understand why my question didn't show up in log4jxx-user.
I posted the question to log4cxx-user, but configured my news reader to 
only fetch log4jxx-user. (Sorry about that)
>> 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".
Thanks for pointing me in the correct direction.

--Eric.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Reading config.xml from jarfile

Posted by Curt Arnold <ca...@apache.org>.
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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org