You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by T E Schmitz <ma...@numerixtechnology.de> on 2004/08/09 18:06:35 UTC

[Configuration] load config files from ddifferent jars

Hello,

I would like to set up a configuration factory specifying a properties 
file which does not reside in the same jar as the composite 
configuration .xml file.

Example:

<configuration>
     <properties fileName="application.properties"/>
     <properties fileName="/biz/prop.properties"/>
     <hierarchicalDom4j fileName="objects/business-objects.xml"/>
</configuration>

It appears that the leading slash is stripped and an attempt is made to 
read biz/prop.properties from the .jar file where above .xml config 
resides.

I notice there is a setBasePath() which would probably solve the problem 
if all composite config files resides below the same basepath. But in my 
case the various config files reside in different jar files.

Is there a way of loading the various config files from different .jar 
files?

-- 


Regards/Gruß,

Tarlika Elisabeth Schmitz

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


RE: [Configuration] load config files from ddifferent jars

Posted by Eric Pugh <ep...@upstate.com>.
Could you maybe submit a unit test?  Basically, create a stripeed down jar,
and put in in /conf.  Also submit a generic ConfigurationFactory settings.
Open a bug in bugzilla and attach this.  That way we can track and not lose
this example.

Eric

> -----Original Message-----
> From: T E Schmitz [mailto:mailreg@numerixtechnology.de]
> Sent: Monday, August 09, 2004 10:12 PM
> To: Jakarta Commons Users List
> Subject: Re: [Configuration] load config files from ddifferent jars
>
>
> Hallo Oliver,
> Thanks for your response.
>
> I tested this on Windoze 2000 but the application will eventually run on
> Linux. But this shouldn't come into it as the properties file resides in
> another jar file (see example below).
> The jar containing the properties file is called biz.jar and the
> properties file is in the root package "biz". Hence I tried to refer to
> the prop file as "/biz/prop.properties". The jar containing the
> composite config .xml is called app.jar. Both jar files are in the
> classpath of the application.
>
> I certainly do not want to have to specify the other jar file using an
> absolute file name.
>
> I got the following exception which shows that the ConfigurationFactory
> is trying to load biz/properties, i.e. a file in the same jar as the
> composite config .xml.
>
> Here's a stack trace snippet.
>
> Caused by: org.apache.commons.configuration.ConfigurationException:
> Could not load from file /biz/prop.properties
> 	at
> org.apache.commons.configuration.PropertiesConfiguration.load(Prop
> ertiesConfiguration.java:107)
> 	at
> org.apache.commons.configuration.PropertiesConfiguration.load(Prop
> ertiesConfiguration.java:90)
> 	... 19 more
> Caused by: java.io.FileNotFoundException: JAR entry biz/prop.properties
> not found in
> K:\Projects\Ffordes\development\ffordes_0-2\build\dist\app.jar
> 	at
> sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection
> .java:97)
> 	at
> sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLCon
> nection.java:107)
> 	at java.net.URL.openStream(URL.java:913)
> 	at
> org.apache.commons.configuration.PropertiesConfiguration.getProper
> tyStream(PropertiesConfiguration.java:134)
> 	at
> org.apache.commons.configuration.PropertiesConfiguration.load(Prop
> ertiesConfiguration.java:102)
>
>
> Regards,
> Tarlika
>
>
>
> Oliver Heger wrote:
> > ConfigurationFactory should work with both relative and absolute file
> > names (at least this is the theory ;-) You should also be able to pass
> > in a complete URL.
> >
> > Which operating system are you working on? If it is Unix/Linux, your
> > configuration file shouldn't make problems (unless there is a
> bug in the
> > methods for loading the configurations). Under Windows you will have to
> > provide a filename like C:\mydir\myproperties.properties. You can also
> > try to specify a file:/ URL pointing to your properties file.
> >
> > T E Schmitz wrote:
> >
> >> Hello,
> >>
> >> I would like to set up a configuration factory specifying a properties
> >> file which does not reside in the same jar as the composite
> >> configuration .xml file.
> >>
> >> Example:
> >>
> >> <configuration>
> >>     <properties fileName="application.properties"/>
> >>     <properties fileName="/biz/prop.properties"/>
> >>     <hierarchicalDom4j fileName="objects/business-objects.xml"/>
> >> </configuration>
> >>
> >> It appears that the leading slash is stripped and an attempt is made
> >> to read biz/prop.properties from the .jar file where above .xml config
> >> resides.
> >>
> >> Is there a way of loading the various config files from different .jar
> >> files?
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


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


Re: [Configuration] load config files from ddifferent jars

Posted by T E Schmitz <ma...@numerixtechnology.de>.
Hallo Oliver,
Thanks for your response.

I tested this on Windoze 2000 but the application will eventually run on
Linux. But this shouldn't come into it as the properties file resides in
another jar file (see example below).
The jar containing the properties file is called biz.jar and the
properties file is in the root package "biz". Hence I tried to refer to
the prop file as "/biz/prop.properties". The jar containing the
composite config .xml is called app.jar. Both jar files are in the
classpath of the application.

I certainly do not want to have to specify the other jar file using an
absolute file name.

I got the following exception which shows that the ConfigurationFactory
is trying to load biz/properties, i.e. a file in the same jar as the
composite config .xml.

Here's a stack trace snippet.

Caused by: org.apache.commons.configuration.ConfigurationException:
Could not load from file /biz/prop.properties
	at
org.apache.commons.configuration.PropertiesConfiguration.load(PropertiesConfiguration.java:107)
	at
org.apache.commons.configuration.PropertiesConfiguration.load(PropertiesConfiguration.java:90)
	... 19 more
Caused by: java.io.FileNotFoundException: JAR entry biz/prop.properties
not found in K:\Projects\Ffordes\development\ffordes_0-2\build\dist\app.jar
	at
sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:97)
	at
sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:107)
	at java.net.URL.openStream(URL.java:913)
	at
org.apache.commons.configuration.PropertiesConfiguration.getPropertyStream(PropertiesConfiguration.java:134)
	at
org.apache.commons.configuration.PropertiesConfiguration.load(PropertiesConfiguration.java:102)


Regards,
Tarlika



Oliver Heger wrote:
> ConfigurationFactory should work with both relative and absolute file 
> names (at least this is the theory ;-) You should also be able to pass 
> in a complete URL.
> 
> Which operating system are you working on? If it is Unix/Linux, your 
> configuration file shouldn't make problems (unless there is a bug in the 
> methods for loading the configurations). Under Windows you will have to 
> provide a filename like C:\mydir\myproperties.properties. You can also 
> try to specify a file:/ URL pointing to your properties file.
> 
> T E Schmitz wrote:
> 
>> Hello,
>>
>> I would like to set up a configuration factory specifying a properties 
>> file which does not reside in the same jar as the composite 
>> configuration .xml file.
>>
>> Example:
>>
>> <configuration>
>>     <properties fileName="application.properties"/>
>>     <properties fileName="/biz/prop.properties"/>
>>     <hierarchicalDom4j fileName="objects/business-objects.xml"/>
>> </configuration>
>>
>> It appears that the leading slash is stripped and an attempt is made 
>> to read biz/prop.properties from the .jar file where above .xml config 
>> resides.
>>
>> Is there a way of loading the various config files from different .jar 
>> files?






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


Re: [Configuration] load config files from ddifferent jars

Posted by Oliver Heger <Ol...@t-online.de>.
ConfigurationFactory should work with both relative and absolute file 
names (at least this is the theory ;-) You should also be able to pass 
in a complete URL.

Which operating system are you working on? If it is Unix/Linux, your 
configuration file shouldn't make problems (unless there is a bug in the 
methods for loading the configurations). Under Windows you will have to 
provide a filename like C:\mydir\myproperties.properties. You can also 
try to specify a file:/ URL pointing to your properties file.

Hope this helps!
Oliver

T E Schmitz wrote:

> Hello,
>
> I would like to set up a configuration factory specifying a properties 
> file which does not reside in the same jar as the composite 
> configuration .xml file.
>
> Example:
>
> <configuration>
>     <properties fileName="application.properties"/>
>     <properties fileName="/biz/prop.properties"/>
>     <hierarchicalDom4j fileName="objects/business-objects.xml"/>
> </configuration>
>
> It appears that the leading slash is stripped and an attempt is made 
> to read biz/prop.properties from the .jar file where above .xml config 
> resides.
>
> I notice there is a setBasePath() which would probably solve the 
> problem if all composite config files resides below the same basepath. 
> But in my case the various config files reside in different jar files.
>
> Is there a way of loading the various config files from different .jar 
> files?
>


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


Re: [Configuration] load config files from ddifferent jars

Posted by T E Schmitz <ma...@numerixtechnology.de>.
Hello Eric,

I'd be happy to make some contributions in return for the excellent 
libraries that Jakarta Commons is providing.
Once I have some time I'll have a look at it and familiarize myself with 
your code conventions.

Best regards,
Tarlika

Eric Pugh wrote:

> Humm..   Not sure on this one...   It seems like what we should be doing is
> actually loading them as a resources..  that way trying to find it is left
> up to whaterver classloader is being used..   so, it shouldn't care what jar
> it is in..  However, not quite sure how to do that..  patches welcome...!
> 
> I am sure you can do what you want, it seems not hard, but I'm not sure..
> Worse comes to worse, skip the configurationfactory, and just do it
> yourself..  but it would be nicer to just patch configurationFactory.
> 
> Eric
> 
> 
>>-----Original Message-----
>>From: T E Schmitz [mailto:mailreg@numerixtechnology.de]
>>Sent: Monday, August 09, 2004 6:07 PM
>>To: commons-user@jakarta.apache.org
>>Subject: [Configuration] load config files from ddifferent jars
>>
>>
>>Hello,
>>
>>I would like to set up a configuration factory specifying a properties
>>file which does not reside in the same jar as the composite
>>configuration .xml file.
>>
>>Example:
>>
>><configuration>
>>     <properties fileName="application.properties"/>
>>     <properties fileName="/biz/prop.properties"/>
>>     <hierarchicalDom4j fileName="objects/business-objects.xml"/>
>></configuration>
>>
>>It appears that the leading slash is stripped and an attempt is made to
>>read biz/prop.properties from the .jar file where above .xml config
>>resides.
>>
>>I notice there is a setBasePath() which would probably solve the problem
>>if all composite config files resides below the same basepath. But in my
>>case the various config files reside in different jar files.
>>
>>Is there a way of loading the various config files from different .jar
>>files?


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


RE: [Configuration] load config files from ddifferent jars

Posted by Eric Pugh <ep...@upstate.com>.
Humm..   Not sure on this one...   It seems like what we should be doing is
actually loading them as a resources..  that way trying to find it is left
up to whaterver classloader is being used..   so, it shouldn't care what jar
it is in..  However, not quite sure how to do that..  patches welcome...!

I am sure you can do what you want, it seems not hard, but I'm not sure..
Worse comes to worse, skip the configurationfactory, and just do it
yourself..  but it would be nicer to just patch configurationFactory.

Eric

> -----Original Message-----
> From: T E Schmitz [mailto:mailreg@numerixtechnology.de]
> Sent: Monday, August 09, 2004 6:07 PM
> To: commons-user@jakarta.apache.org
> Subject: [Configuration] load config files from ddifferent jars
>
>
> Hello,
>
> I would like to set up a configuration factory specifying a properties
> file which does not reside in the same jar as the composite
> configuration .xml file.
>
> Example:
>
> <configuration>
>      <properties fileName="application.properties"/>
>      <properties fileName="/biz/prop.properties"/>
>      <hierarchicalDom4j fileName="objects/business-objects.xml"/>
> </configuration>
>
> It appears that the leading slash is stripped and an attempt is made to
> read biz/prop.properties from the .jar file where above .xml config
> resides.
>
> I notice there is a setBasePath() which would probably solve the problem
> if all composite config files resides below the same basepath. But in my
> case the various config files reside in different jar files.
>
> Is there a way of loading the various config files from different .jar
> files?
>
> --
>
>
> Regards/Gruß,
>
> Tarlika Elisabeth Schmitz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


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