繁体   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