Websphere 8.5에서 실행중인 웹 응용 프로그램의 WEb-INF 폴더에서 등록 정보 파일을로드하려고합니다. 나는 위치 나 또한 서블릿 컨텍스트를 사용하여 시도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;
}
}
에서 파일을로드하는 코드 아래 사용하고 있지만, 그 또한 나를 NULL 제공합니다. 나는 그것을 해결하는 모든 가능한 방법을 시도했지만 불행히도 나는 그것을 할 수 없습니다. 나는 또한 내 폴더 구조를 제공하고있다. 이 바보 같은 질문 경우
실례하시기 바랍니다,하지만 난 정말 그것에 대해 어떤 생각을 못하고 있어요.
아는대로 속성 파일은 resources 폴더에 있습니다. Maven을 사용하는 경우 pom.xml에 리소스 폴더를 정의 할 수 있습니다. 대개 그들은'/ src/main/resources'에 있습니다. 거기서부터 다음과 같이 접근 할 수 있습니다 :'MyClass.class.getResourcesAsStream (...) ' – Al1