Here is the layout of my project:
src/
test/
resources/
ares/
file1.xml
file2.xml
Here is the layout of the Jenkins workspace:
my-module/
target/
test-classes/
ares/
file1.xml
file2.xml
Under eclipse the tests run without any error. On Jenkins, the tests just fail. Jenkins is unable to locate the resources. Below are some output from the test execution:
MyClass.class.getResourceAsStream(/ares/file1.xml) => java.io.BufferedInputStream@4f4b2f1a
MyClass.class.getResourceAsStream(ares/file1.xml) => null
Thread.currentThread().getContextClassLoader().getResourceAsStream(/ares/file1.xml) => null
Thread.currentThread().getContextClassLoader().getResourceAsStream(ares/file1.xml) => java.io.BufferedInputStream@5d402eeb
MyClass.class.getClassLoader().getResourceAsStream(/ares/file1.xml) => null
MyClass.class.getClassLoader().getResourceAsStream(ares/file1.xml) => java.io.BufferedInputStream@20c87621
MyClass.class.getResourceAsStream(/ares/file1.xml) => null
MyClass.class.getResourceAsStream(ares/file1.xml) => null
Thread.currentThread().getContextClassLoader().getResourceAsStream(/ares/file1.xml) => null
Thread.currentThread().getContextClassLoader().getResourceAsStream(ares/file1.xml) => null
MyClass.class.getClassLoader().getResourceAsStream(/ares/file1.xml) => null
MyClass.class.getClassLoader().getResourceAsStream(ares/file1.xml) => null
As you can see Jenkins doesn't find my resource.
What am I missing?
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.