2012-03-02 2 views
0

tomcat에서 실행되는 웹 응용 프로그램이 있습니다. 자원을 넣고 싶습니다.리소스 파일을 JAR 파일에 넣을 수 있습니까?

resources.jar 

configuration.xml 

하지만하려고하면

new File("/conf/configuration.xml") 

발견되지 않았다.

경로를 다른 방식으로 구성해야합니까?

Thread.currentThread().getContextClassLoader().getResource("/conf/configuration.xml"); 

또는

Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/configuration.xml"); 

가 첫 번째는 URL, 두 번째 InputStream를 반환합니다 웹 응용 프로그램에서 실행하는 경우

+0

응용 프로그램의 클래스 경로에 jar 파일을 구성 했습니까? – developer

+1

[jar 파일 내로드 파일] (http://stackoverflow.com/questions/4548699/load-file-within-a-jar) – home

+0

의 가능한 복제본 classpath에서 의미? webapps/mywebapplication/WEB-INF/lib에있는이 항아리. 나는이 폴더에있는 모든 항아리가 classpath에 있다고 생각한다. – user710818

답변

2

, 당신은 ContextClassLoader 사용해야합니다.

관련 문제