为什么詹金斯(Jenkins)无法加载资源? [英] Why Jenkins fails to load the resources?
问题描述
这是我的项目的布局:
src/
test/
resources/
ares/
file1.xml
file2.xml
这是Jenkins工作区的布局:
Here is the layout of the Jenkins workspace:
my-module/
target/
test-classes/
ares/
file1.xml
file2.xml
在日食下运行的测试没有任何错误. 在詹金斯身上,测试只是失败了. Jenkins无法找到资源. 以下是测试执行的一些输出:
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
您可以看到Jenkins找不到我的资源.
As you can see Jenkins doesn't find my resource.
我想念什么?
推荐答案
我终于解决了我的问题.在类路径上,该文件名为/ares/file1.xml
,而在我的代码中,我将该文件称为/ares/file1.XML
.您是否注意到大写的XML
?
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
?
在Windows上,由于文件名不区分大小写,因此没有区别. 在Linux上,失败是因为文件名区分大小写.
On Windows, there is no difference since filenames are case insensitive. On Linux, it fails because filenames ARE case sensitive.
最终的想法是,当您在与目标平台不同的平台上进行编码时,首选小写文件名.
这篇关于为什么詹金斯(Jenkins)无法加载资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!