Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Reading properties file from WEB-INF/classes

Thread view: 
Dundonald - 07 Oct 2007 09:23 GMT
Properties file stored in WEB-INF/classes.

There are numerous ways to read properties files, but I'd like to know
what your opinions are on the best way to read from the WEB-INF/
classes directory given that I could deploy my war file to any server
on any platform not knowing how a server is configured, i.e. with its
real paths etc.
Manish Pandit - 07 Oct 2007 10:52 GMT
> Properties file stored in WEB-INF/classes.
>
[quoted text clipped - 3 lines]
> on any platform not knowing how a server is configured, i.e. with its
> real paths etc.

getResourceAsStream() should give you the resouece that is in WEB-INF/
classes.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAs
Stream(java.lang.String
)

-cheers,
Manish
Lew - 07 Oct 2007 16:54 GMT
Dundonald wrote:
>> Properties file stored in WEB-INF/classes.
>>
[quoted text clipped - 3 lines]
>> on any platform not knowing how a server is configured, i.e. with its
>> real paths etc.

> getResourceAsStream() should give you the resouece that is in WEB-INF/
> classes.
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAs
Stream(java.lang.String
)
(Also available from java.lang.Class.)

<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResou
rceAsStream(java.lang.String
)>
will do the same thing rooted at the application context.
> Returns the resource located at the named path as an InputStream object.
...
> The path must begin with a "/" and is interpreted as relative to the current context root.
...
> This method is different from java.lang.Class.getResourceAsStream,
> which uses a class loader.
> This method allows servlet containers to make a resource available to a servlet from
> any location, without using a class loader.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.