You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Captain Cid <ca...@indiatimes.com> on 2011/02/17 09:36:45 UTC

Reading a file in tomcathome/conf folder

I wish to keep configuration property file outside my war. Suppose i keep it
tomcathome/conf/myfile.properties 
How can I read it using classloader from my webapp application code. I am
not able to access it.

I tried using this.getClass().getClassLoader() or even
this.getClass().getClassLoader().getParent() but coudnt !
-- 
View this message in context: http://old.nabble.com/Reading-a-file-in-tomcathome-conf-folder-tp30947709p30947709.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Reading a file in tomcathome/conf folder

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Konstantin,

On 2/17/2011 5:23 AM, Konstantin Kolinko wrote:
> 2011/2/17 Captain Cid <ca...@indiatimes.com>:
>>
>> Yes ..got your point...using spring its easy though
>>
>> My only question is ,
>>
>> can it be accessed using classloader and getResource()
>>
> 
> Why? Just use:
> 
> new FileInputStream(new File(System.getProperty("catalina.base"),
> "conf/yourfile.properties"));

Heh. We always ride people for using the filesystem and here Konstantin
goes suggesting that someone use it :)

Cid, the short answer is that catalina.base isn't available via any
default ClassLoader. If you wanted to, you could place the file into
Tomcat's lib directory, but that has it's disadvantages, too.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1kFOkACgkQ9CaO5/Lv0PBMiwCeP4saNJjge0H4MNdGjmsj8GAX
B6QAoKCVtUtGi1thNck0t2/rCPxPdt1L
=sHvu
-----END PGP SIGNATURE-----

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


Re: Reading a file in tomcathome/conf folder

Posted by Pratyush Chandra <co...@yahoo.com>.
Thanks that worked...although i was hoping to retrieve it using
classloader...


Konstantin Kolinko wrote:
> 
> 2011/2/17 Captain Cid <ca...@indiatimes.com>:
>>
>> Yes ..got your point...using spring its easy though
>>
>> My only question is ,
>>
>> can it be accessed using classloader and getResource()
>>
> 
> Why? Just use:
> 
> new FileInputStream(new File(System.getProperty("catalina.base"),
> "conf/yourfile.properties"));
> 
> Best regards,
> Konstantin Kolinko
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Reading-a-file-in-tomcathome-conf-folder-tp30947709p30972865.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Reading a file in tomcathome/conf folder

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/2/17 Captain Cid <ca...@indiatimes.com>:
>
> Yes ..got your point...using spring its easy though
>
> My only question is ,
>
> can it be accessed using classloader and getResource()
>

Why? Just use:

new FileInputStream(new File(System.getProperty("catalina.base"),
"conf/yourfile.properties"));

Best regards,
Konstantin Kolinko

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


Re: Reading a file in tomcathome/conf folder

Posted by Captain Cid <ca...@indiatimes.com>.
Yes ..got your point...using spring its easy though

My only question is ,

can it be accessed using classloader and getResource()


Brett Delle Grazie-3 wrote:
> 
> Hi,
> 
> On 17 February 2011 08:36, Captain Cid <ca...@indiatimes.com> wrote:
>>
>> I wish to keep configuration property file outside my war. Suppose i keep
>> it
>> tomcathome/conf/myfile.properties
>> How can I read it using classloader from my webapp application code. I am
>> not able to access it.
>>
>> I tried using this.getClass().getClassLoader() or even
>> this.getClass().getClassLoader().getParent() but coudnt !
> 
> Rather than trying to look up the config file path on the classpath
> you could simply
> ask the administrator to supply it in a context parameter override.
> 
> That way the administrator decides where it should go, not you and you
> can supply
> an internal default if you wish.
> 
> If you're using Spring this is very easily accomplished with their
> ServletContextPropertyPlaceholderConfigurer
> class
> 
> hope this helps
> 
> -- 
> Best Regards,
> 
> Brett Delle Grazie
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Reading-a-file-in-tomcathome-conf-folder-tp30947709p30948198.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Reading a file in tomcathome/conf folder

Posted by Brett Delle Grazie <br...@gmail.com>.
Hi,

On 17 February 2011 08:36, Captain Cid <ca...@indiatimes.com> wrote:
>
> I wish to keep configuration property file outside my war. Suppose i keep it
> tomcathome/conf/myfile.properties
> How can I read it using classloader from my webapp application code. I am
> not able to access it.
>
> I tried using this.getClass().getClassLoader() or even
> this.getClass().getClassLoader().getParent() but coudnt !

Rather than trying to look up the config file path on the classpath
you could simply
ask the administrator to supply it in a context parameter override.

That way the administrator decides where it should go, not you and you
can supply
an internal default if you wish.

If you're using Spring this is very easily accomplished with their
ServletContextPropertyPlaceholderConfigurer
class

hope this helps

-- 
Best Regards,

Brett Delle Grazie

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