可以使用插件修改资源和字节代码,以便依赖注入将我们重新定位的包吗?我不这么认为。
我将 javax.transaction.TransactionManager 重写并重新定位到org.me.shaded.javax ...并且我使用它的代码似乎正常运行但是org.infinispan:infinispan-core尝试依赖使用原始包名称注入,无法找到TransactionManager并抛出此错误:
Caused by: java.lang.NoSuchMethodException: java.lang.Object.injectDependencies(..., javax.transaction.TransactionManager, ...)
当我查看我的超级jar时,我发现infinispan-core-component-metadata.dat包含引用javax而不是阴影包的字符串。
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<minimizeJar>false</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<shadedArtifactAttached>true</shadedArtifactAttached>
<relocations>
<relocation>
<pattern>javax.transaction</pattern>
<shadedPattern>org.me.shaded.javax.transaction</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<excludes>
<exclude>org.apache.hbase:*</exclude>
<exclude>org.apache.ant:*</exclude>
<exclude>org.eclipse.jetty:*</exclude>
<exclude>org.springframework:*</exclude>
<exclude>geronimo-spec</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<excludes>
<exclude>webapps/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.infinispan:infinispan-core</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
<filter>
<artifact>org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec</artifact>
<excludes>
<exclude>javax/transaction/**</exclude>
</excludes>
</filter>
<filter>
<artifact>javax.transaction:jta</artifact>
<includes>
<include>javax/transaction/**</include>
</includes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>