2014-01-13 6 views
0

I는 예를로드하므로 웹 단편 (3 서블릿 사양)을 사용하여 ServletContext.getResourceAsStream ("access.xml")을 통해 내 WAR의/WEB-INF/lib /에있는 라이브러리에있는 META-INF/resources/access.xml 파일. (=> 널)를 작동하지 않습니다 ServletContext.getRealPath ("access.xml")와 같은 일을ServletContext.getRealPath()가 웹 조각과 함께 작동합니까?

.

사양 상태 :

The getRealPath method takes a String argument and returns a String representation of a file on the local file system to which a path corresponds. Resources inside the META-INF/resources directory of JAR file must be considered only if the container has unpacked them from their containing JAR file when a call to getRealPath() is made, and in this case MUST return the unpacked location.

항아리 포장을 풀지 않았다 내 컨테이너 (톰캣),이 문제가 될 것 같다? Tomcat이 항아리를 어떻게 풀 수 있습니까? WAR를 포장 할 때 항아리를 꺼내야합니까?

답변

0

예, getResourcesAsStream()은 항상 작동합니다. 그러나 getRealPath()는 그렇지 않습니다.

답변 : 웹 조각과 함께) getRealPath를 (사용하지 마십시오.

0

그래서 당신이 무엇을하려는 지에 따라 달라집니다. 포함 된 라이브러리 종속성에서 파일의 위치를 ​​가져 오려고하는 경우 확실하지 않습니다. 당신이 access.xml 파일의 내용을 읽을하고자하는 경우에 당신은

new InputStreamReader(context.getResourcesAsStream("access.xml")); 

를 사용할 수있는 다음 파일의 내용을 얻기 위해 InputStreamReader와 함께 작동합니다.