This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
No, you cannot do that. The Java EE spec states that nothing outside a WAR can have access to things inside a WAR. the correct way to fix this is move the common resources outside the WAR and place them into a JAR in the EAR.
The incorrect way to kludge this is to change the useJBossWebLoader and java2ClassLoadingCompliance properties of the WarDeployer bean in the
server/xxx/deployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xml file. Be aware that making this change can lead to some surprises.
I have re factored my project and now I have the images in my war's root. (i.e. I do not need to go to another war to get them). However I am still having problems getting a hold of that resource.
In the debugger I can see that my classloader is something like ...../myEar.ear/myWar.war, so I have the classloader for the war in which my images live. Are there other reasons why my call to getResource("images") would return null?
This is in a Servlet class which lives in my war, shouldn't I be able to do this?
It all depends on what you are doing. From the code you posted it appears that your servlets are serving images. For that specific code the images need to be in the classpath, but in general your servlets could get the images form anywhere on your server, even from a directory completely external to you WAR, or even external to the app server . I have seen people use servlets to serve images in external directories when the collection of images can change; this way it is easy to add images because the WAR doesn't have to be rebuilt.
Of course, if your HTML output includes img tags that reference the image files directly, then the image files cannot be within the WEB-INF directory because that is not accessible from outside the WAR (i.e., not from the browser).