getClass().getResource("/").getFile().toString().substring(1)在window和linux下的不同。,
分享于 点击 12654 次 点评:47
getClass().getResource("/").getFile().toString().substring(1)在window和linux下的不同。,
背景:项目在window下运行正常,在linux下运行不正常,tomcat还没报错记录(好奇怪。。。)
原因:
1.getClass().getResource("/").getFile().toString().substring(1)获取资源路径在window和linux下不一样。
String path2 = getClass().getResource("/").getFile().toString().substring(1);
String fileNameCtx = path2 + "/META-INF/spring/applicationContext.xml";
LOGGER.debug("Start produce applicationContext.xml,path is "+fileNameCtx);
window下是正确的;
路径:E:/develop/Java/apache-tomcat-7.0.70/webapps/innovate/WEB-INF/classes//META-INF/spring/applicationContext.xml
linux下面不正确
路径是:usr/local/src/apache-tomcat-7.0.70/webapps/innovate/WEB-INF/classes//META-INF/spring/applicationContext.xml
注意:前面缺少了/,这个路径在linux下是不存在的(查了好长时间,泪奔。。)
而异常时通过e.printStackTrace()打印的,实际就是system.err,日志文件得用LOGGER.err()才能写到日志文件中。
相关文章
- 暂无相关文章
用户点评