标签搜索

class path resource 'xxx.yaml' cannot be opened

wangpig
2023-07-25 / 0 评论 / 128 阅读 / 正在检测是否收录...

class path resource 'xxx.yaml' cannot be opened

class path resource [ xxx.yaml]cannot be opened because it dose not exist。
类路径下无法打开一个文件,因为它不存在。

这是一个存在/src/main/resources/ 目录下的文件,理论上,在maven 打包后能够读到的。但是反复报错。

通过运行时debug, 执行

System.getProperty("java.class.path")

打印类路径,能够明确的看到

C:\Users\xxx\xxx\target\classes;
C:\xxx\xxx\xxx\xxx\xxx.jar;
...

点开到classes 目录下,能够看到application.yml 等都存在,但是自定义的 xxx.yaml 的确不存在。
蓦然想起因为流水线要求打包的jar包要在最外层的target下,内部module 的pom.xml是有一定设置的。
而哪些文件被打包进来是有限制的:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <inculude>**/*.yml</inculude>
        <inculude>**/*.xml</inculude>
        <inculude>**/*.properties</inculude>
    </resource>
</resources>

唯独少了yaml,所以相应的补充一个*/.yaml 即可。

总结一下就是,遇到问题还是看看具体报错信息,逐步定位,其实不难。

0

评论 (0)

取消

浙公网安备 33020502001051号

浙ICP备2023015387号-1