Eclipse 和 m2e:如何自动从 JAR 中排除资源文件夹?

发布于 2025-01-01 21:47:12 字数 337 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘落散花 2025-01-08 21:47:12

我可以通过 pom.xml 中的以下配置实现相同的目的:-

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <excludes>
                    <exclude>*.xml</exclude>
                    <exclude>*.properties</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

I could achieve the same with following configuration in pom.xml :-

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <excludes>
                    <exclude>*.xml</exclude>
                    <exclude>*.properties</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>
殊姿 2025-01-08 21:47:12

使用 maven-resources-plugin 指定您不希望包含在 jar 中的配置文件。

Use the maven-resources-plugin to specify the config files you don't wish to include in your jar.

瞄了个咪的 2025-01-08 21:47:12

最后,可以在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文