How can I find a non-Java resource in a WAR at runtime?

I need to run a shell script at runtime from a WAR that I am running on Tomcat.

So I put my script theScript.sh in the src / main / resources directory (because, yes, I use Maven). This directory is on the class path, I checked it.

In the code, I want to copy my script to the temp directory. So I tried to get it through my ClassLoader:

URL myURL = ClassLoader.getSystemResource("theScript.sh");
if (myURL == null) {
    LOG.error("Couldn't find the resource");
}

And guess what? Yes, "Could not find a resource" continues to appear everywhere in my magazines.

Any idea what I'm doing wrong here?

My environment is a traditional Eclipse / Tomcat thing.

+3
source share
2

System cloassloader, , Tomcat JRE.

, WAR. , ServletContext (javadoc) getResource getClassLoader().getResource.

ServletContext, "", - , , , WAR. -

this.getClass().getClassLoader().getResource("xyz");

this - , WAR.

+3

getClass(). getClassLoader(). getResource() getResourceAsStream()? , .

0

All Articles