Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用web应用读取属性文件(使用JSF的Maven web应用)_Jsf_Web Applications_Properties File - Fatal编程技术网

无法使用web应用读取属性文件(使用JSF的Maven web应用)

无法使用web应用读取属性文件(使用JSF的Maven web应用),jsf,web-applications,properties-file,Jsf,Web Applications,Properties File,我在默认包中有一个属性文件:hibernate.properties。我试图从另一个包中的类中读取它:com.somepackage.SomeClass 在普通桌面应用程序中,以下输入流正在工作: InputStream is = getClass().getResourceAsStream("/hibernate.properties"); 但是我的web应用程序(一个使用Netbeans创建的maven web应用程序,依赖于JSF2.2) 我尝试了以下几种选择: 使用类: getClas

我在默认包中有一个属性文件:hibernate.properties。我试图从另一个包中的类中读取它:com.somepackage.SomeClass

在普通桌面应用程序中,以下输入流正在工作:

InputStream is = getClass().getResourceAsStream("/hibernate.properties");
但是我的web应用程序(一个使用Netbeans创建的maven web应用程序,依赖于JSF2.2)

我尝试了以下几种选择:

使用类:

getClass().getResourceAsStream("/hibernate.properties");
使用外部上下文:

FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/hibernate.properties");
使用上下文类加载器:

Thread.currentThread().getContextClassLoader().getResourceAsStream("/hibernate.properties");

每一个都返回null。如何读取默认包中的属性文件?

我假设您查找的文件位置错误<代码>休眠。属性通常不保存在部署的根目录中。打开.war文件并查找
hibernate.properties
的位置。如果将应用程序部署到
localhost:8080/app1
,则需要调用
/app1/
以访问部署内容

嗯。奇怪的是,当我从Netbeans向导创建hibernate.cfg.xml时,它出现在“othersources(src/main/resources)”中。我以为是insde:。让我把所有的资源放在src/main/resources中,打开你的.war,比如winrar,看看它到底在哪里。我自己创建了hibernate.properties文件。我的意思是你需要看看你的.war是如何创建的。战争中的位置很重要