关于java web的相对路径问题!
if(sessionFactory == null)
{
File cfgFile = new File("./WEB-INF/hibernate.cfg.xml");
Configuration cfg = new Configuration().configure(cfgFile);
//cfg.addResource("hibernate.cfg.xml");
// cfg.configure();
sessionFactory = cfg.buildSessionFactory();
if(sessionFactory == null)
{
int i = 0;
i++;
}
报错!
org.hibernate.HibernateException: could not find file: .\WEB-INF\hibernate.cfg.xml
我就想知道。File里面的路径是怎么搜索的。比如,这段代码所在的类(xx.java)文件,要被编译成.class文件,会生成到build/classes/com/xx/yy这种目录下面,那么我写的代码的相对路径是不是要相对于他的class文件所在的目录呢?
但是我试过了,好像不对。在这个工程里面的相对路径到底是怎么回事?
比如,我的hibernate.cfg.xml放在web-inf这个目录下面的。那么这个相对路径该如何来写呢?
请各位赐教。。呵呵!