cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "" <>
Subject AW: Loading a configuration file from a jar
Date Thu, 19 Oct 2006 14:18:44 GMT
Hi Omar

Try using the classloader to load your properties file from the classpath (if you drop it
in the classes directory or another jar-file)

try {
    	is = Configuration.class.getClassLoader().getResourceAsStream("config.xml");
} catch (Exception e) {

The other way would be to use a relative path. As I recall all relative paths are relative
to the WEB-INF directory of your webapp. (I hope I'm correct with this)

I have used both ways successfully. I wouln't recommend using absolute paths and load resources
entirely outside your application since some Servlet containers might restrict access to those
files and maybe the user, the servlet engine is running under has no access to any files outside.


[ c h r i s t o f e r   d u t z ]

univativ GmbH & Co. KG
Robert-Bosch-Str. 7, 64293 Darmstadt

fon: 0 61 51 / 66 717 - 21
fax: 0 61 51 / 66 717 - 29

Darmstadt, Stuttgart, Karlsruhe, Düsseldorf

-----Ursprüngliche Nachricht-----
Von: Omar Adobati [] 
Gesendet: Donnerstag, 19. Oktober 2006 15:45
Betreff: 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(){
	File configFile = new File("/");	
	  configURL = configFile.toURL();
	}catch (Exception ex){
        //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:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message