我正在制作一个带有依赖关系的自定义 azure-service-bus 客户端的 jar,在我的情况下(Carlos/Robert)/ issue#466解决方法(maven-shade-plugin)不起作用。
我总是得到同样的错误:
Service or property not registered: com.microsoft.windowsazure.services.servicebus.ServiceBusContract class com.sun.jersey.api.client.Client
注意:我刚刚在这里找到了可能与同一问题相关的另一张公开票:问题#465
此错误的根本原因是以下错误资源:
META-INF/services/com.microsoft.windowsazure.core.Builder$Exports
azure-core
和(0.8.3)依赖项都azure-servicebus
使用嵌入“要导出的包”列表的相同文件(相同名称和相同位置)。这 2 个文件应该合并。
我可悲的解决方法是使用 maven-assembly 的 2 次执行:
- 步骤 A) 第一次执行创建一个依赖目录,
- 步骤 B)第二次执行附加我的固定
Builder$Exports
资源版本,删除 MS 签名文件(安全问题),并制作最终的 jar 文件。
此解决方案尚不可接受,因为未从 azure 依赖项中选择固定资源。我有自己的额外资源。但是今天我没有其他解决方法。
固定的 MS 合并结果文件(src/main/resources)是:
文件名
META-INF/services/com.microsoft.windowsazure.core.Builder$Exports
文件内容
com.microsoft.windowsazure.services.servicebus.Exports
com.microsoft.windowsazure.services.servicebus.implementation.Exports
com.microsoft.windowsazure.core.pipeline.apache.Exports
com.microsoft.windowsazure.core.pipeline.jersey.Exports
com.microsoft.windowsazure.core.utils.Exports
com.microsoft.windowsazure.credentials.Exports
com.microsoft.windowsazure.management.configuration.Exports
pom插件定义:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>dir-jar-with-dependencies</id><!-- step A -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/dir_jardeps.xml</descriptor>
</descriptors>
<finalName>busclient</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>jar-with-dependencies-ms-patch</id><!-- step B -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>${mainclass}</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/assembly/jardeps_mspatch.xml</descriptor>
</descriptors>
<finalName>busclient</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
文件src/assembly/dir_jardeps.xml
:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dir-jar-with-dependencies</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
文件src/assembly/dir_jardeps.xml
:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dir-jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes/META-INF</directory>
<outputDirectory>META-INF</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}/busclient</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>META-INF/services/com.microsoft.windowsazure.core.Builder$Exports</exclude>
<!-- MS jars are signed : remove signatures -->
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>