Maven:在JAR的META-INF中包含文件 [英] Maven: include files in JAR's META-INF
问题描述
我正在使用Maven构建一个Java项目,我有几个文件, CHANGELOG
和 LICENSE
,我想复制到JAR文件中的 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>
...
但这也将这两个文件复制到 classes / META-INF
编译时的目录。
but that also copies those two files to the classes/META-INF
directory when compiling.
所以我希望这些文件包含在JAR文件中,但是没有其他地方。有没有办法做到这一点?
So I'd like the files to be included in the JAR file, but nowhere else. Is there a way to do this?
推荐答案
您无需指定任何自定义maven配置来满足您的需求。< br>
在 src / main / resources
中,只创建一个 META-INF
文件夹并放置文件在这里。
通过这种方式,您可以在构建的JAR的 META-INF
文件夹中找到它们。
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.
此外,您应该删除<$ c $中添加的< resource>
元素c> pom.xml 因为它将默认资源文件夹更改为项目的根目录而不是默认的 src / main / resources
。
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
.
这篇关于Maven:在JAR的META-INF中包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!