11

我正在使用 Maven 构建一个 Java 项目,并且我有几个文件,CHANGELOG并且LICENSE,我想将它们复制到META-INFJAR 文件内的目录中。

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

<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 文件中,但没有其他地方。有没有办法做到这一点?

4

3 回答 3

13

您无需指定任何自定义 Maven 配置来满足您的需求。

src/main/resources中,只需创建一个META-INF文件夹并将您的文件放在这里。
这样,您可以在META-INF构建的 JAR 的文件夹中找到它们。

此外,您应该删除 <resource>您在 中添加的元素,pom.xml因为它将默认资源文件夹更改为项目的根目录,而不是默认的src/main/resources.

于 2016-08-08T19:11:37.490 回答
1

如果要将文件和目录添加到 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>
于 2019-11-27T21:12:18.577 回答
0

通过添加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

战争示例输出 战争输出示例

于 2021-01-05T07:38:24.253 回答