我正在使用Maven构建一个Java项目,我有两个文件,CHANGELOG
和LICENSE
,我想将它们复制到JAR文件内的META-INF
目录中。
到目前为止,我得到的工作如下:
<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
目录。
因此,我希望这些文件包含在JAR文件中,而不是其他地方。有没有办法做到这一点?
发布于 2016-08-09 03:11:37
您不需要指定任何自定义maven配置来满足您的需求。
在src/main/resources
中,只需创建一个META-INF
文件夹并将文件放在此处即可。
这样,您就可以在构建的JAR的META-INF
文件夹中找到它们。
此外,您应该删除在pom.xml
中添加的<resource>
元素,因为它会将默认的资源文件夹更改为项目的根目录,而不是默认的src/main/resources
。
发布于 2019-11-28 05:12:19
如果想要将文件和目录添加到META-INF文件夹中,请在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>
发布于 2021-01-05 15:38:24
通过添加webResources修改您的pom
<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>
考虑要在以下位置找到的config.properties文件
src / main / resources / META-INF / config.properties
War示例输出
https://stackoverflow.com/questions/38833373
复制相似问题