繁体   English   中英

如何在不同模块的jar中复制maven中的资源

[英]How to copy resources in maven in the jar of a different module

我在 java 项目中有以下模块结构

-根
-- 主模块
-- 另一个模块

并使用 maven-resources-plugin,我试图将主模块中存在的一些资源复制到另一个模块

主模块的 pom.xml 中使用以下代码段,我运行 mvn clean install,因此 basedir 是主模块的基本目录。

<execution>
    <id>copy-resources-json2</id>
    <phase>process-resources</phase>
    <goals>
        <goal>copy-resources</goal>
    </goals>
    <configuration>
        <outputDirectory>${session.executionRootDirectory}/Another-Module/src/main/resources/config</outputDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources/config</directory>
            </resource>
        </resources>
    </configuration>
</execution>

虽然它确实在项目中本地复制资源,但问题是,当我检查另一个模块的 jar 时,配置目录中不存在资源。

请问我在做什么错。

将 Maven 配置文件移动到要使用它们的模块是一个更好的做法。

但是如果你有这样的结构:

.
 |-- my-module
 |   `-- pom.xml
 `-- parent
     `-- pom.xml

也许你想用这样的相对路径来构建你的 pom.xml:

<project>
...
    <parent>
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
        <version>1</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>
...
</project>

您可以在Maven 文档中查看 pom 结构的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM