Eclipse 和 m2e:如何自动从 JAR 中排除资源文件夹?
我有一个 Maven 3 项目。我将项目配置文件存储到 src/main/config 目录中。我使用带有 m2e 插件的 Eclipse。我希望配置文件位于类路径上,因此我将 src/main/config 目录声明为父 POM 中的资源目录。但是,我不希望配置文件位于我的 JAR 中。 当我将 src/main/config 声明为资源目录,并且使用 m2eclipse 更新项目配置时,它会自动添加 src/main/config 作为源文件夹,但排除为“**”。 Maven 构建器插件将资源添加到类路径中。
但是,我希望我的配置文件位于类路径上,但不在我的 JAR 中。
我怎样才能做到这一点?
谢谢
I have a Maven 3 project. I store the project config files into the src/main/config directory. I use Eclipse with m2e plugin. I want the config files to be on the classpath, so I declare the src/main/config directory as a resource directory in the parent POM. But, I don't want the config files to be in my JAR.
When I declare src/main/config as a resource directory, and that I update the project configuration with m2eclipse, it automatically adds src/main/config as a source folder but with excluded="**". The Maven builder plugin adds the resources to the classpath.
But, I want my config files to be on the classpath but not in my JAR.
How can I do that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以通过 pom.xml 中的以下配置实现相同的目的:-
I could achieve the same with following configuration in pom.xml :-
使用 maven-resources-plugin 指定您不希望包含在 jar 中的配置文件。
Use the maven-resources-plugin to specify the config files you don't wish to include in your jar.
最后,可以在maven-jar-plugin中进行配置。 maven-resources-plugin 将 src/main/config 的内容复制到 target/classes 目录,因为 src/main/config 在 POM 中被声明为资源。而且,为了从 JAR 中排除文件,我使用了 maven-jar-plugin 元素中的元素来排除我的配置文件。
Finally, it may be configured in the maven-jar-plugin. The maven-resources-plugin copies the content of src/main/config to the target/classes directory because src/main/config is declared as resource in the POM. And, to exclude the files from the JAR, I used element in the maven-jar-plugin element to exclude my config files.