如何编写maven build来为classpath添加资源? [英] How can I write maven build to add resources to classpath?
问题描述
我正在使用带有简单maven安装的maven构建一个jar。
如果我将文件添加到 src / main / resources
,它可以在类路径中找到,但它有一个配置文件夹,我希望该文件可以移动但移动它在config文件夹中使它从类路径中消失。
I am building a jar using maven with simple maven install.
If I add a file to src/main/resources
it can be found on the classpath but it has a config folder where I want that file to go but moving it inside the config folder makes it disappear from the classpath.
推荐答案
如果你在 src /中放置任何东西main / resources
目录,然后默认情况下它将以最终的 *。jar
结尾。如果你从其他项目中引用它并且在类路径中找不到它,那么你就会遇到以下两个错误之一:
If you place anything in src/main/resources
directory, then by default it will end up in your final *.jar
. If you are referencing it from some other project and it cannot be found on a classpath, then you did one of those two mistakes:
-
* .jar
未正确加载(可能是路径中的拼写错误?) - 您没有正确处理资源,例如:
/src/main/resources/conf/settings.properties
在类路径中显示为classpath:conf / settings.properties
*.jar
is not correctly loaded (maybe typo in the path?)- you are not addressing the resource correctly, for instance:
/src/main/resources/conf/settings.properties
is seen on classpath asclasspath:conf/settings.properties
这篇关于如何编写maven build来为classpath添加资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!