Why Jenkins fails to load the resources?

I finally solved my issue. On the classpath, the file is named /ares/file1.xml while in my code I was calling the file /ares/file1.XML. Did you notice the uppercased XML?

On Windows, there is no difference since filenames are case insensitive. On Linux, it fails because filenames ARE case sensitive.

Final thought, when you code on a platform different from the target platform prefer lower case filenames.


I had this problem with similar symptoms but different cause and different solution.

In my case the issue was that the Jenkins server was a Windows machine and the full path on the server to the location of the resources started with C:\Program Files (x86)\... with spaces. Those spaces get encoded to %20 if you need to get is as a File instead of a stream using new File(getClass().getResource(fileName).getFile()). Here fileName is a string that contains the name of the resource. I solved the problem by adding a call to URLDecoder.decode. This creates no problems when there are no spaces or you're not on Windows (as far as I've seen) but it solves the problem if you get a space in the name somewhere along the line. The full call is then:

 new File(URLDecoder.decode(getClass().getResource(fileName).getFile(), "UTF-8"))

I pieced this together from several questions, but none put it all together for the Jenkins case, hence my answer here. Other relevant Q&A:

  • Java: how to get a File from an escaped URL?
  • How do you unescape URLs in Java?
  • Resource files not found from JUnit test cases