是否有方法使用Maven在META/ services中创建自定义服务文件?这就是使用Ant:https://ant.apache.org/manual/Tasks/jar.html的方法
我知道可以在源代码中创建一个资源/META/,并在其中放置我想要的任何服务文件。然后,Maven将自动将这些文件拖到我的JAR中。这不能解决我的问题。
服务文件的内容会根据我正在构建的JAR类型而改变,所以我不能简单地在源代码文件夹中创建它。
在我的源代码中有多个版本的服务文件,让Maven排除我不需要的版本,也不能解决我的问题。这是因为服务文件需要是一个特定的名称;拥有多个版本的文件将阻止这一点。
摘要:是否有方法使用Maven创建服务文件(META/services)的内容?
谢谢!
发布于 2017-02-05 20:07:29
如果可以创建相当数量的此类服务文件,则可以将它们存储在项目中的单独路径中。例如:

然后,您可以有选择地包含像这样的pom.xml文件(再举一个pom.xml功能强大但冗长的例子):
<properties>
<service.declaration.dir>src/serviceManifests</service.declaration.dir>
<service.files.path>META-INF/services</service.files.path>
</properties>
<profiles>
<profile>
<id>foo</id>
<build>
<resources>
<resource>
<directory>${service.declaration.dir}</directory>
<includes>
<include>${service.files.path}/foo</include>
</includes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>bar</id>
<build>
<resources>
<resource>
<directory>${service.declaration.dir}</directory>
<includes>
<include>${service.files.path}/bar</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>要包含这两个文件,您将运行:
mvn clean package -P foo -P bar要只包含foo文件,您将运行:
mvn clean package -P foohttps://stackoverflow.com/questions/42056142
复制相似问题