I have some resource files that are in the classpath of my web application (inside a JAR, if that matters). I know I can access the contents of those resources by calling e.g. SomeClassLoader.getResourceAsStream( "/samples/myscript.txt" )
. I have tested this in the past in both exploded and non-exploded WAR files with success.
However, to integrate with some other existing classes in my app, I need to provide an URLConnection object to that file. I tested and confirmed that calling getResource("/samples/myscript.txt").openConnection()
works in exploded WARs (additionaly, debugging revealed that the result is a file:///
URL to the exploded file).
Question: will that method also work on non-exploded ("packaged?") WARs?
(I currently do not have easy access to a server that deploys wars without exploding them, hence why I'm asking instead of outright trying it. Also, some servers (e.g. Jetty, Tomcat -- even with unpackWARs="false"
) allows non-exploded deployments, but behind the scenes they unpack the war, effectively behaving like an exploded deployment -- and, evidently, working correctly. I think the servers that gave me trouble in the past were Websphere and Weblogic).