转:解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误
2007-07-19 04:59
483 查看
转:解决java.util.MissingResourceException:Can'tfindbundleforbasenamecom...config,localezh_CN错误
Solvejava.util.MissingResourceException:Can'tfindbundleforbasenamecom...config,localezh_CN
atjava.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
atjava.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
atjava.util.ResourceBundle.getBundle(ResourceBundle.java:576)
Youknowjavaislookingforapropertiesfileinaspecificlocale.Youmaybebaffledwhyjavakeepscomplainingitcan'tfindapropertiesfilethatisrightthere.Afewthingstokeepinmindwhendebuggingthistypeoferrors:
Theseresourcepropertiesfilesareloadedbyclassloader,similartojavaclasses.Soyouneedtoincludetheminyourruntimeclasspath.
Theseresourceshavefully-qualified-resource-name,similartoafully-qualified-class-name,excerptyoucan'timportaresourceintoyourjavasourcefile.Why?becauseitsnametakestheformofastring.
Forinstance,youhaveaprojectlike
Forthisstatementin
Forthisstatementinandincludeconfig.jarintheclasspath.[/code]
Youmaybewonderingwhyitismadesoconfusing?Thebenefitsaretwo-fold,asIseeit:
Locationtransparency.Atruntime,config.propertiesisNOTafile,it'sjustaaloadableresource.config.properitesmaynotexistinyourprojectatall,andthepersonwhowroteScrap.javamayhaveneverseenthisresource.AURLClassLoadercanfinditinanetworkpathorURLatruntime.Thisisespeciallyimportantforserver-sidecomponentssuchasEJB,Servlet,JSP,etc,whoarenormallynotallowedtoaccessfilesystems.Whenyouaskclassloadersforaresource,itsphysicallocationbecomesirrelevant.
Namespacemechanism.Havingapackageallowsmultiplepackagestohaveresourceswiththesameshortnamewithoutcausingconflicts.Thisisnodifferentfromjavapackagesandxmlnamespaces.
Solvejava.util.MissingResourceException:Can'tfindbundleforbasenamecom...config,localezh_CN
atjava.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
atjava.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
atjava.util.ResourceBundle.getBundle(ResourceBundle.java:576)
Youknowjavaislookingforapropertiesfileinaspecificlocale.Youmaybebaffledwhyjavakeepscomplainingitcan'tfindapropertiesfilethatisrightthere.Afewthingstokeepinmindwhendebuggingthistypeoferrors:
Theseresourcepropertiesfilesareloadedbyclassloader,similartojavaclasses.Soyouneedtoincludetheminyourruntimeclasspath.
Theseresourceshavefully-qualified-resource-name,similartoafully-qualified-class-name,excerptyoucan'timportaresourceintoyourjavasourcefile.Why?becauseitsnametakestheformofastring.
ResourceBundle.getBundle("config")tellstheclassloadertoloadaresourcenamed
"config"withdefaultpackage(thatis,nopackage).ItdoesNOTmeanaresourceinthecurrentpackagethathasthereferencingclass.
ResourceBundle.getBundle("com.cheng.scrap.config")tellstheclassloadertoloadaresourcenamed
"config"withpackage
"com.cheng.scrap."Itsfully-qualified-resource-nameis
"com.cheng.scrap.config"
Forinstance,youhaveaprojectlike
C:/ws/netbeans5/scrap> |build.xml +---build |/---classes |/---com |/---cheng |/---scrap |Scrap.class | +---src |/---com |/---cheng |/---scrap |config.properties |Scrap.java
Forthisstatementin
Scrap.java:ResourceBundleconfig=ResourceBundle.getBundle("config");towork,youwillneedto
cpsrc/com/cheng/scrap/config.propertiesbuild/classes/suchthat
config.propertiesisdirectlyunder
classes,andatthesamelevelas
com.Alternatively,youcanput
config.propertiesintoa
config.jarsuchthat
config.propertiesisattherootof
config.jarwithoutanysubdirectories,andinclude
config.jarintheclasspath.
Forthisstatementin
Scrap.java:ResourceBundleconfig=ResourceBundle.getBundle("com.cheng.scrap.config");towork,youwillneedto
cpsrc/com/cheng/scrap/config.propertiesbuild/classes/
com/cheng/scrap/suchthat
config.propertiesisdirectlyunder
classes
/
com/cheng/scrap/,andatthesamelevelas
scrap.Alternatively,youcanput
com/cheng/scrap/
config.properties(alongwiththelongsubdirectories)intoa
config.jar,
Youmaybewonderingwhyitismadesoconfusing?Thebenefitsaretwo-fold,asIseeit:
Locationtransparency.Atruntime,config.propertiesisNOTafile,it'sjustaaloadableresource.config.properitesmaynotexistinyourprojectatall,andthepersonwhowroteScrap.javamayhaveneverseenthisresource.AURLClassLoadercanfinditinanetworkpathorURLatruntime.Thisisespeciallyimportantforserver-sidecomponentssuchasEJB,Servlet,JSP,etc,whoarenormallynotallowedtoaccessfilesystems.Whenyouaskclassloadersforaresource,itsphysicallocationbecomesirrelevant.
Namespacemechanism.Havingapackageallowsmultiplepackagestohaveresourceswiththesameshortnamewithoutcausingconflicts.Thisisnodifferentfromjavapackagesandxmlnamespaces.
相关文章推荐
- 转:解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误
- 解决java.util.MissingResourceException: Can't find bundle for base name configContext, locale zh_CN
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- java.util.MissingResourceException: Can't find bundle for base name init, locale zh_CN问题的处理
- java.util.MissingResourceException: Can't find bundle for base name i18n, locale zh_CN
- 关于:java.util.MissingResourceException: Can't find bundle for base name merchantInfo, locale zh_CN
- JSF java.util.MissingResourceException: Can't find bundle for base name javax.faces.Messages, locale zh_CN
- 解决方法:java.util.MissingResourceException Can't find bundle for base name
- MissingResourceException: Can't find resource for bundle java....错误解决
- 解决 java.util.MissingResourceException: Can't find bundle for base name com...con
- java.util.MissingResourceException
- 分享以下编译错误:java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException的一种解决方法
- Caused by: java.lang.ClassNotFoundException: FilterConfig错误的解决办法
- java.util.MissingResourceException
- java.util.MissingResourceException
- java.util.MissingResourceException
- Caused by: java.lang.IllegalArgumentException: Javassist library is missing in classpath! ..错误解决
- Grade编译错误 java.util.zip.ZipException: duplicate entry的解决方法
- 我的Android进阶之旅------>Android编译错误java.util.zip.ZipException: duplicate entry的解决方法
- java.util.concurrent.ExecutionException 错误解决。