Websphere 8.5上で実行されているWebアプリケーションのWEb-INFフォルダからプロパティファイルを読み込もうとしています。私はまた、サーブレットコンテキストを使用して試してみましたが、そのも私にNULLを与えた場所からファイルをロードするためのコードの下にWebsphere 8.5サーバーのweb-infフォルダからプロパティファイルを読み込めません。
public class Init {
private final String WEB_INF_DIR_NAME="WEB-INF";
private String web_inf_path;
private final Properties APP_PROPERTIES =null;
InputStream inputStream = null;
public String getWebInfPath() throws IOException {
if (web_inf_path == null) {
web_inf_path = URLDecoder.decode(Init.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF8");
web_inf_path=web_inf_path.substring(0,web_inf_path.lastIndexOf(WEB_INF_DIR_NAME)+WEB_INF_DIR_NAME.length()).substring(1);
}
inputStream = Init.class.getResourceAsStream("/config/localhost/accountservice.properties");
// inputStream = this.getClass().getClassLoader().getResourceAsStream("/config/localhost/accountservice.properties");
if (inputStream != null) {
APP_PROPERTIES.load(inputStream);
}
System.out.println(APP_PROPERTIES.getProperty(AccountServiceDataAccessConstants.INET_LIBRARY_NAME)); // Here i am getting NULL
return web_inf_path;
}
}
を使用しています。私はそれを解決するためにすべての可能な方法を試みたが、残念ながら私はそれを行うことができません。私はまた、私のフォルダ構造を与えています。
これは愚かな質問である場合は恐れ入りますが、私は本当にそれについてどんな考えを取得していないですしてください。
私が知る限り、プロパティファイルはresourcesフォルダにあります。 Mavenを使用している場合は、リソースフォルダをpom.xmlに定義することができます。通常、 '/ src/main/resources'にあります。そこから、あなたはそれにアクセスできます: 'MyClass.class.getResourcesAsStream(...)' – Al1