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