Maven: include files in JAR's META-INF

旧巷老猫 提交于 2019-12-07 07:19:24

问题


I'm using Maven to build a Java project, and I've got a couple files, CHANGELOG and LICENSE, that I'd like to copy to the META-INF directory inside the JAR file.

So far what I've got working is the following:

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

but that also copies those two files to the classes/META-INF directory when compiling.

So I'd like the files to be included in the JAR file, but nowhere else. Is there a way to do this?


回答1:


You don't need to specify any custom maven configuration to address your need.
In src/main/resources, creating simply a META-INF folder and place your files here.
In this way, you could find them in the META-INF folder of the built JAR.

Besides, you should remove the <resource> element you added in the pom.xml since it changes the default resource folder to the root of the project instead of the default src/main/resources.




回答2:


If you want to add files and a directory to the META-INF folder use this code in your 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>


来源:https://stackoverflow.com/questions/38833373/maven-include-files-in-jars-meta-inf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!