Maven 在构建 JAR 文件时需要包含文件

Maven require inclusion of file when building JAR file

我需要在 Maven 构建的 JAR 文件中包含一个文件。 所以我按照这个参考文档并在我的pom.xml中添加了一个元素:https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

然而,这包括文件(如果存在)- 我需要使该文件成为最终结果 JAR 文件的要求。有没有办法指定必须包含该文件?

您可以尝试强制规则:

https://maven.apache.org/enforcer/enforcer-rules/requireFilesExist.html

这会检查文件是否存在,否则会中断构建。