I'm trying to read a properties file within a web-app under JBoss. Thesetup 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 nameidmwswrapper.properties, locale en_US2007-08-03 14:52:08,734 INFO [STDOUT]java.util.MissingResourceException: Can't find bundle for base nameidmwswrapper.properties, locale en_USAnyone have any ideas? I've tried other methods of reading the file,but it cannot be 'found'. Doc sayprops file must be in classpath. WEB-INF/classes is in the classpath.Any help greatly appreciated!
|
|
0
|
|
|
|
Reply
|
wgblackmon (36)
|
8/3/2007 10:00:52 PM |
|
On Aug 3, 3:00 pm, ddog <wgblack...@yahoo.com> wrote:> 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!Hi,Try changing ResourceBundle.getBundle("idmwswrapper.properties") toResourceBundle.getBundle("idmwswrapper").-cheers,Manish
|
|
0
|
|
|
|
Reply
|
Manish
|
8/3/2007 11:03:26 PM
|
|
ddog wrote:> 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.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#getResource(java.lang.String)><http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(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(java.lang.String)><http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream(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.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
8/3/2007 11:15:43 PM
|
|
On Aug 3, 6:15 pm, Lew <l...@lewscanon.nospam> wrote:> ddog wrote:> > 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.>> 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.ht...)>> <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.ht...)>> 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#getR...)>> <http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getR...)>>> 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.>> --> LewThanks guys - I'll give these 2 methods a shot....
|
|
0
|
|
|
|
Reply
|
ddog
|
8/4/2007 12:25:16 AM
|
|
|
3 Replies
552 Views
(page loaded in 0.113 seconds)
|