java.util.MissingResourceException: Can't find bundle for base name
2009-05-23 14:51
671 查看
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
Forthisstatementinandinclude
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.
才知道那个属性文件也要加上路径的。于是又开始新征程。这样为了配活,再来。
staticResourceBundlerb=ResourceBundle.getBundle(ReadSource.class.getPackage().toString().substring(8)+".info");
这样就解决了路径问题,只要属性文件和读取文件在一起就可以了。它们俩放哪倒是无所谓了。呵呵。
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,
config.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.
才知道那个属性文件也要加上路径的。于是又开始新征程。这样为了配活,再来。
staticResourceBundlerb=ResourceBundle.getBundle(ReadSource.class.getPackage().toString().substring(8)+".info");
这样就解决了路径问题,只要属性文件和读取文件在一起就可以了。它们俩放哪倒是无所谓了。呵呵。
相关文章推荐
- 解决方法:java.util.MissingResourceException Can't find bundle for base name
- Notes for "java.util.MissingResourceException Can't find bundle for base name"
- 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 configContext, locale zh_CN
- 关于:java.util.MissingResourceException: Can't find bundle for base name merchantInfo, locale zh_CN
- java.util.MissingResourceException: Can't find resource for bundle oracle.sysman.db.rsc.LoginResourc
- java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle,
- MissingResourceException: Can't find resource for bundle java....错误解决
- 安卓工作室 android studio 汉化后,报错。 设置界面打不开。Can't find resource for bundle java.util.PropertyResourceBundle
- 安卓工作室 android studio 汉化后,报错。 设置界面打不开。Can't find resource for bundle java.util.PropertyResourceBundl
- Can't find bundle for base name MessageResource, locale zh_CN
- Android Studio的中文包错误:Can't find resource for bundle java.util.PropertyResourceBundle, key configurab
- Eclipse CDT 调试故障解决:Can't find resource for bundle java.util.PropertyResourceBundle
- Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN错误处理
- Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN解决方案
- Can't find bundle for base name 的解决方法
- Can't find bundle for base name 包名.xxxx.文件名,locale 语言简称_国家简称
- 关于SpringMVC MockMvc测试 Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN错误
- Can't find bundle for base name Message, locale zh_CN
- Android studio中遇到Can't find bundle for base name configd, locale zh_CN解决办法