将生成的构建文件添加到类路径

发布于 2025-01-05 07:53:13 字数 193 浏览 4 评论 0原文

在构建过程中,我通过包含构建信息的 Maven 属性插件 (properties-maven-plugin) 生成 build.properties 文件。

将此文件包含在生成的 jar 中的最佳方法是什么?我不想将其放入 src/main/resources 目录,因为这会污染我的默认资源目录。

是否没有像源代码那样的“生成资源”目录?

During my build I generate a build.properties files via the maven properties plugin (properties-maven-plugin) containing build information.

What's the best way to have this file included in the generated jar? I don't want to put it into the src/main/resources directory as this would pollute my default resource directory.

Is there not a "generated-resources" directory as there is with source?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

逐鹿 2025-01-12 07:53:13

我认为有一个默认的 generated-resources 目录,但目前我找不到任何相关文档。您始终可以在 pom 中配置其他资源目录:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${project.build.directory}/generated-resources</directory>
        </resource>
    </resources>
    ...
</build>

I thought there was a default generated-resources directory, but I can't find any documentation on that at the moment. You can always configure additional resource directories in your pom:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${project.build.directory}/generated-resources</directory>
        </resource>
    </resources>
    ...
</build>
自控 2025-01-12 07:53:13

将生成的源放在 target/ generated-sources

有一个名为 build-helper 允许您将该文件夹添加到源文件夹列表中。

Place generated sources in target/generated-sources

There is a plugin called build-helper that allows you to add that folder to the source-folders list.

风情万种。 2025-01-12 07:53:13

您可以使用 Maven 程序集插件来组织包中的文件和文件集。看看 http://maven.apache.org /plugins/maven-assemble-plugin/advanced-descriptor-topics.html
我认为这就是你所需要的。

You can use maven assembly plugin to organize files and filesets in packages. have a look at http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html
I think it is what you need.

橘虞初梦 2025-01-12 07:53:13

您可以将文件输出到任何目录,并将该资源目录添加到

you can output your files to any directory and add that resource directory to your <resources> of your <build>

沙沙粒小 2025-01-12 07:53:13

您应该将其放在 target/classes 目录中

(现在仅从 target 修复),我认为这比公认的要好。因为不再需要将此资源作为资源处理

You should put it in the target/classes directory

(fixed now from just target) and I think that this is better than the accepted one. As there is no need to process this resource as resource anymore

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