【发布时间】:2015-06-28 18:12:13
【问题描述】:
我正在尝试在战争中访问我的属性文件。代码正在运行,但是当我将代码导出到战争中并使用 Fiddler 使用 POST(带有接受的输入)时,它找不到 config.properties。 (NullPointerException)
输入和网络服务运行正常。只是想找出一种在使用战争时编辑我的属性的方法。
一些事实:
-
我已经创建了一个 RetreivePropertiesClass。这使用:
properties.load(this.getClass() .getResourceAsStream("/WEB-INF/config.properties")); -
我的属性文件路径:
/com.webapp/WebContent/WEB-INF/config.properties -
我正在尝试使用以下属性数据:
String url = RetreiveProperties.getUrl(); String driver = RetreiveProperties.getDriver(); String username = RetreiveProperties.getUsername(); String password = RetreiveProperties.getPassword(); // line below causes the NullPointerException Class.forName(driver); -
使用吸气剂:
public static String getDriver() { return driver = properties.getProperty("jdbc.driver"); } -
war部署时,properties文件在:
webapps\com.webapp1\WEB-INF\config.properties -
配置属性:
jdbc.url = jdbc:postgresql://127.0.0.1:2222/gisdb jdbc.driver = org.postgresql.Driver jdbc.username = postgres jdbc.password = admin
我已经尝试过给出here 和here 的示例。由于未加载属性文件,因此不断给出 NullPointerException。
谁能把我推向正确的方向?
干杯!
【问题讨论】:
-
查看打包后的war文件,属性文件的路径是什么?
-
啊,忘记说了。它在 C:\Users\myusername\Downloads\apache-tomcat-8.0.21-windows-x64\apache-tomcat-8.0.21\webapps\com.webapp1\WEB-INF
标签: java web-applications properties war