如何使用 Jboss7.1 从 java 代码中加载图像等资源?
这曾经与 Jboss4 一起工作:
this.getClass().getClassLoader().getResourceAsStream("/myapp/includes/images/image1.png");
现在这返回 null。
现在使用 Jboss7 在 java 代码中加载资源的最佳实践是什么?
我做了一些测试:
URL url = this.getClass().getResource("");
System.out.println(url);
url = this.getClass().getResource("../../../");
System.out.println(url);
url = this.getClass().getResource("../../../../");
System.out.println(url);
url = this.getClass().getResource("../../../../../");
System.out.println(url);
url = this.getClass().getResource("includes");
System.out.println(url);
13:33:49,143 INFO [stdout] (http--127.0.0.1-8080-1) vfs:/C:/Eclipse/apps/jboss-as-7.1.1.Final/standalone/deployments/my-ea.ear/my-web.war/WEB-INF/classes/com/xxx/yyy/beans/jsf/
13:33:49,144 INFO [stdout] (http--127.0.0.1-8080-1) vfs:/C:/Eclipse/apps/jboss-as-7.1.1.Final/standalone/deployments/my-ea.ear/my-web.war/WEB-INF/classes/com/xxx/
13:33:49,150 INFO [stdout] (http--127.0.0.1-8080-1) jar:file:/C:/Eclipse/apps/jboss-as-7.1.1.Final/modules/javax/activation/api/main/activation-1.1.1.jar!/com/
13:33:49,151 INFO [stdout] (http--127.0.0.1-8080-1) file:/C:/Eclipse/apps/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources/
13:33:49,152 INFO [stdout] (http--127.0.0.1-8080-1) null