Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: include files in JAR's META-INF

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?

like image 309
Julián Urbano Avatar asked Aug 08 '16 15:08

Julián Urbano


1 Answers

You don't need to specify any custom maven configuration to address your need.

In src/main/resources, simply create 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.

like image 122
davidxxx Avatar answered Sep 28 '22 01:09

davidxxx