Julián Urbano
Julián Urbano

Reputation: 8488

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?

Upvotes: 14

Views: 34927

Answers (5)

Harri Pesonen
Harri Pesonen

Reputation: 13

I tried adding META-INF/resources/org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable with the following content:

org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable

But after doing the jar package, it still contained only:

org.glassfish.jersey.server.wadl.internal.WadlAutoDiscoverable
org.glassfish.jersey.server.internal.monitoring.MonitoringAutodiscoverable

Then I manually edited jar so that it contains:

org.glassfish.jersey.server.wadl.internal.WadlAutoDiscoverable
org.glassfish.jersey.server.internal.monitoring.MonitoringAutodiscoverable
org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable

Then application works fine. Now I just need to find a way to add this missing line to that file.

Upvotes: 0

Edward D. Wilson
Edward D. Wilson

Reputation: 361

If you want to add your files to META-INF when creating a WAR, you can create your own META-INF folder in webapp directory.

src/main/webapp/META-INF

Upvotes: 0

Ronald Coarite
Ronald Coarite

Reputation: 4726

Modify your pom by adding webResources

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

Consider the config.properties file to be found in

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

War example output war output example

Upvotes: 1

davidxxx
davidxxx

Reputation: 131326

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.

Upvotes: 22

Edson Su&#225;rez
Edson Su&#225;rez

Reputation: 31

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>

Upvotes: 3

Related Questions