1
내가 SRC에서 리소스에 액세스하려고 MA/주/웹 애플리케이션/서블릿 컨텍스트는 null을 반환
내가 자바 1.8.0_101를 사용하고 불행하게도 3.0.3
을 받는다는하고, 그것에서 일하고 다른 유닉스 환경에서 하나의 환경 및되지는
@Named
@ApplicationScoped
public class TestClass {
private static final String RESOURCE = "/resources/css/test.css";
private String css = "";
public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext servletContext) throws IOException {
String pathString = servletContext.getRealPath(RESOURCE);
System.out.println("path string: " + pathString);
byte[] data = Files.readAllBytes(Paths.get(pathString));
css = new String(data, "UTF-8");
}
public String getCss() {
return css;
}
public String format(Object o) {
if (o instanceof List) {
List<?> list = (List<?>) o;
String text = list.toString();
return text.substring(1, text.length() - 1);
}
return o == null ? "" : o.toString();
}
}