Classpath resourcesï¼ã¯ã©ã¹ãã¹ãããªã½ã¼ã¹ãèªã¿è¾¼ããããããjarã®ä¸ã¨ããï¼
Webã§ã¯ãã¾ãæ°ã«ãããã¨ã®ãªãã£ããªã½ã¼ã¹ã®é
ç½®å ´æãªã®ã§ããã
ã¹ã¿ã³ãã¢ãã³ã§é
å¸ããå ´åã©ãã«ç½®ãã¦ã©ãèªã¿è¾¼ãã®ãã¨ã
ï¼jarã«å
¨é¨åºããå ´åã¨ãã絶対ãã¹æå®ã§ããªãã¨ãï¼
propertiesãã¡ã¤ã«ãjarã®ä¸ã«å ¥ãã¦ãã¾ãããã®ã§ãã
ã§ãããããã°Seasarããã¯ä½åãdiconãã¡ã¤ã«ãjarã®ä¸ã«ãã£ããªã¼ã¨æããè²ã
ã®ããã¦ã¿ã¦
ããããã¯ã©ã¹ãã¼ãã¼ã使ãã®ããã¨ãªãã¾ãããï¼ResourceUtilãã¸ããåç
§ããã¦ãããã¾ããï¼ã
ãã®æµãã§
http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html
ã®ã¹ãããªè¡¨ã«ãã©ãçããã®ã§ã³ãã£ã¦ããã¾ãã
Behavioral differences
Method Parameter format Lookup failure behavior Usage example ClassLoader.getResourceAsStream() "/"-separated names; no leading "/" (all names are absolute) Silent (returns null) this.getClass().getClassLoader().getResourceAsStream("some/pkg/resource.properties") Class.getResourceAsStream() "/"-separated names; leading "/" indicates absolute names; all other names are relative to the class's package Silent (returns null) this.getClass().getResourceAsStream("resource.properties") ResourceBundle.getBundle() "."-separated names; all names are absolute; .properties suffix is implied Throws unchecked java.util.MissingResourceException ResourceBundle.getBundle("some.pkg.resource")
- ClassLoader.getResourceAsStream()
- ã¯ã©ã¹ãã¹ã®é ããã
- åºåãã¯ã/ãã§ã
- é ã«ã/ãã¯å ¥ããªãã
- Class.getResourceAsStream()
- ã¯ã©ã¹ã®ããå ´æããã
- åºåãã¯ã/ãã§ã
- å é ã«ã/ããå ¥ããããã¯ã©ã¹ãã¹ã®é ããã
- ResourceBundle.getBundle()
- ã¯ã©ã¹ãã¹ã®é ããã
- åºåãã¯ã.ãã§ã