簡體   English   中英

Maven:在 JAR 的 META-INF 中包含文件

[英]Maven: include files in JAR's META-INF

我正在使用 Maven 構建一個 Java 項目,我有幾個文件CHANGELOGLICENSE ,我想將它們復制到 JAR 文件內的META-INF目錄中。

到目前為止,我的工作如下:

<build>
    <resources>
        <resource>
            <directory>${project.basedir}</directory>
            <includes>
                <include>CHANGELOG</include>
                <include>LICENSE</include>
            </includes>
            <targetPath>META-INF</targetPath>
        </resource>
    </resources>
    <plugins>
        ...

但這也會在編譯時將這兩個文件復制到classes/META-INF目錄。

所以我希望這些文件包含在 JAR 文件中,但沒有其他地方。 有沒有辦法做到這一點?

您不需要指定任何自定義 Maven 配置來滿足您的需求。

src/main/resources ,只需創建一個META-INF文件夾並將您的文件放在此處。
這樣,您就可以在構建的 JAR 的META-INF文件夾中找到它們。

此外,您應該刪除在pom.xml添加的<resource>元素,因為它將默認資源文件夾更改為項目的根目錄,而不是默認的src/main/resources

如果要將文件和目錄添加到 META-INF 文件夾,請在 pom.xml 中使用此代碼

   <build>
        <finalName>CustomJsfComponents</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**.xml</include>
                    <include>**resources/**</include>
                </includes>
                <targetPath>META-INF</targetPath>
            </resource>
        </resources>
    </build>

通過添加webResources修改你的 pom

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <webResources>
                    <resource>
                        <directory>target/classes/META-INF/</directory>
                        <includes>
                            <include>*.*</include>
                        </includes>
                        <targetPath>META-INF/</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

考慮要在其中找到的 config.properties 文件

src / main / resources / META-INF / config.properties

戰爭示例輸出戰爭輸出示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM