java的classpath配置文件_Java Classpath及.properties配置文件
private static final String CONFIG_FILE = "logmonitor.properties";
ClassLoader cl =ClassLoader.getSystemClassLoader();
input= cl.getResourceAsStream(fileName);
需要改成
ClassLoader cl = PerfCoalescingStatisticsUtil.class.getClassLoader();
input=cl.getResourceAsStream(fileName);
prop.load(input);
http://stackoverflow.com/questions/1921238/getclass-getclassloader-is-null-why
http://jeecookbook.blogspot.com/2013/07/java-why-you-should-not-use.html
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource%28java.lang.String%29
http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getSystemClassLoader()
繼續相關的,如果配置文件是在一個jar包中,而這個jar包被上一級的工程所引用,如何保證在jar包中的代碼能夠找到這個配置文件
事實上找到的有用的信息如下
http://www.mkyong.com/applet/how-do-java-applet-access-files-inside-applet-jar-file/
http://stackoverflow.com/questions/5054435/reading-file-in-jar-using-relative-path
http://stackoverflow.com/questions/941754/how-to-get-a-path-to-a-resource-in-a-java-jar-file
http://stackoverflow.com/questions/3627426/loading-a-file-relative-to-the-executing-jar-file
在這種情形下,因為jar包的問題,文件不能如一個妥當的目錄被找到
/data/web/apache-tomcat-6.0.43/bin/file:/data/web/apache-tomcat-6.0.43/webapps/ROOT/WEB-INF/lib/log-monitor-api-1.0-SNAPSHOT-jar-with-dependencies.jar!/xcs-online.properties (No such file or directory)
這種情形下,有file:和.jar!標識符,還好找嗎?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的java的classpath配置文件_Java Classpath及.properties配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乐高机器人java程序代码_用JAVA编
- 下一篇: mysql8中怎么增删一列_关于MySQ