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 / August 2007

Tip: Looking for answers? Try searching our database.

Loading properties file in .war under JBoss - where do they belong?

Thread view: 
ddog - 03 Aug 2007 23:00 GMT
I'm trying to read a properties file within a web-app under JBoss. The
setup follows:

Location of properties file in war file is:
WEB-INF/classes

// code to load properties file is:
ResourceBundle props =
ResourceBundle.getBundle("idmwswrapper.properties",
Locale.getDefault(), this.getClass().getClassLoader());

ERROR READING PROPERTIES FILE.... Can't find bundle for base name
idmwswrapper.properties, locale en_US
2007-08-03 14:52:08,734 INFO  [STDOUT]
java.util.MissingResourceException: Can't find bundle for base name
idmwswrapper.properties, locale en_US

Anyone have any ideas? I've tried other methods of reading the file,
but it cannot be 'found'. Doc say
props file must be in classpath. WEB-INF/classes is in the classpath.

Any help greatly appreciated!
Manish Pandit - 04 Aug 2007 00:03 GMT
> I'm trying to read a properties file within a web-app under JBoss. The
> setup follows:
[quoted text clipped - 18 lines]
>
> Any help greatly appreciated!

Hi,

Try changing ResourceBundle.getBundle("idmwswrapper.properties") to
ResourceBundle.getBundle("idmwswrapper").

-cheers,
Manish
Lew - 04 Aug 2007 00:15 GMT
> I'm trying to read a properties file within a web-app under JBoss. The
> setup follows:
[quoted text clipped - 16 lines]
> but it cannot be 'found'. Doc say
> props file must be in classpath. WEB-INF/classes is in the classpath.

I don't know about JBoss particularly, but generally there are two roads:
Use the ServletContext:
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResou
rce(java.lang.String
)>
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResou
rceAsStream(java.lang.String
)>
ServletContext.getResourceAsStream( String path )
> The path must begin with a "/" and is interpreted as relative to the current context root.

Typically you'd gather a resource from a resources subdirectory of the webapp
or of the WEB-INF/:
  context.getResourceAsStream( "resources/my.properties" )

The other way is to use a ClassLoader, either directly or through the
corresponding Class methods:
<http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getResource(jav
a.lang.String
)>
<http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsSt
ream(java.lang.String
)>

These methods search the class path, not the web app context, so instead of
starting at, for example:
  http://your.host:8080/webapp/
it starts looking at the application's WEB-INF/classes subdirectory and other
classpath locations.

For web apps the ServletContext version would probably work better.

Signature

Lew

ddog - 04 Aug 2007 01:25 GMT
> > I'm trying to read a properties file within a web-app under JBoss. The
> > setup follows:
[quoted text clipped - 44 lines]
> --
> Lew

Thanks guys - I'll give these 2 methods a shot....


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.