web项目启动时一个启动类InitListener加载WEB-INF下xml文件 路径问题

py911118 2014-09-03 12:01:27
项目启动时
public class InitListener implements ServletContextListener {

public void contextDestroyed(ServletContextEvent arg0) {

}

public void contextInitialized(ServletContextEvent arg0) {
File file = new File("tree.xml");
TreeManager.path = file.getPath();
TreeManager.getTree();
}

}


项目启动时候就执行这个类(这个类是在src下的) 可是这个tree.xml 是在WEB-INF下的 找不到路径
要如何做?
...全文
264 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Thomas.Sir 2014-09-05
  • 打赏
  • 举报
回复
这样试试:File file = new File(getClass().getClassLoader().getResource("treexml").getPath());

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧