簡體   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