问题如下:我需要在META-INF中生成文件,以便使用ServiceLoader进行注册。FWIW,这是maven 3.0.4。指向pom.xml文件的完整链接是here。
为了生成这些文件,我使用this plugin,如下所示:
<properties>
<serviceName>com.github.fge.msgsimple.serviceloader.MessageBundleProvider</serviceName>
</properties>
<!-- .... -->
<plugin>
<groupId>eu.somatik.serviceloader-maven-plugin</groupId>
<artifactId>serviceloader-maven-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<services>
<param>${serviceName}</param>
</services>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>但是,生成的文件(META-INF/services/xxxx)没有进入生成的jar中,所以我不得不求助于此(您的眼睛可能会出血):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="jarname"
value="${project.name}-${project.version}.jar"/>
<property name="victim"
value="${project.build.directory}/${jarname}"/>
<property name="serviceFile"
value="${project.build.directory}/classes/META-INF/services/${serviceName}"/>
<echo>${victim}</echo>
<echo>${serviceFile}</echo>
<jar destfile="${victim}" update="true">
<zipfileset file="${serviceFile}"
prefix="META-INF/services/"/>
</jar>
</target>
</configuration>
</execution>
</executions>
</plugin>我知道阴影插件。我已经试过了,连续几个小时都在和它斗争,一点也没有成功。它只是不包括文件。以上是唯一对我有效的解决方案。
但这种解决方案是不可持续的。我还希望生成具有依赖关系的jar,在这种情况下,需要附加服务文件;而上面的解决方案只适用于没有依赖关系的jar……
那么,你需要什么插件才能让整个事情无缝地工作呢?您如何配置它?
发布于 2013-06-14 22:22:12
你有没有考虑过汇编插件?我发现它非常强大。http://maven.apache.org/plugins/maven-assembly-plugin/
https://stackoverflow.com/questions/17105131
复制相似问题