You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Omar Adobati <om...@gmail.com> on 2006/10/19 15:43:55 UTC

Loading a configuration file from a jar

Good Morning,

  I have developed a jar file and I need to load some configuration
parameters from a .properties file placed outside of the jar itself.

The jar file is under $cocoon/WEB-INF/lib directory and the
.properties file too.
Now, the problem is that my own class (that extends the
java.util.Properties class) can't locate the properties file.
Here is the code I'm actually using:

public ConfigUtility(){
	super();
	File configFile = new File("/nptl.im.properties");	
	try{
	  configURL = configFile.toURL();
	}catch (Exception ex){
           ex.printStackTrace();
	}
		
        //do some other useful stuff
  }

I'm running cocoon 2.1.18 with tomcat 5.5.x and JDK 1.5

Thanks for your help :)

-- 
Omar Adobati

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Loading a configuration file from a jar

Posted by Geert Josten <ge...@daidalos.nl>.
I think you should be looking in the direction of:

	import java.util.Locale;
	import java.util.MissingResourceException;
	import java.util.ResourceBundle;

	...

	Locale locale = Locale.getDefault();
      try {
        	resources = ResourceBundle.getBundle(
        			"my.package.MyProperties",
        			locale);
      } catch (MissingResourceException e) { 
		...
	}

you need to put a file MyProperties.properties in a folder my/packages/
inside any jar that you put into WEB-INF/lib/.

Kind regards,
Geert

> 
   
 
Drs. G.P.H. Josten
Consultant
 
 

Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl
KvK 27164984


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.
 

> Van: Omar Adobati [mailto:omar.adobati@gmail.com] 
> Verzonden: donderdag 19 oktober 2006 15:44
> Aan: users@cocoon.apache.org
> Onderwerp: Loading a configuration file from a jar
> 
> Good Morning,
> 
>   I have developed a jar file and I need to load some 
> configuration parameters from a .properties file placed 
> outside of the jar itself.
> 
> The jar file is under $cocoon/WEB-INF/lib directory and the 
> .properties file too.
> Now, the problem is that my own class (that extends the 
> java.util.Properties class) can't locate the properties file.
> Here is the code I'm actually using:
> 
> public ConfigUtility(){
> 	super();
> 	File configFile = new File("/nptl.im.properties");	
> 	try{
> 	  configURL = configFile.toURL();
> 	}catch (Exception ex){
>            ex.printStackTrace();
> 	}
> 		
>         //do some other useful stuff
>   }
> 
> I'm running cocoon 2.1.18 with tomcat 5.5.x and JDK 1.5
> 
> Thanks for your help :)
> 
> --
> Omar Adobati
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org