4

我用maven-shade-plugin建了一个项目,但是遇到了一个我处理不了的问题。有两个jar几乎有相同的类并且路径相同,aspectjweaver.jar和aspectjrt.jar,当打包jar,我得到警告“重复的类已经存在于......”。我尝试使用“重定位”属性来重定位类,但问题是,如何重新识别两个 jar 中的类?接下来是我的 Pom.xml 的一部分。org.apache.maven.plugins maven-shade-plugin 1.3.1

            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>

                        <filters>
                            <filter>
                                <artifact>org.aspectj:aspectjrt</artifact>
                                <includes>
                                    <include>*</include>
                                </includes>
                            </filter>
                        </filters>
                        <relocations>
                            <relocation>
                                <pattern>org.aspectj</pattern>
                                <shadedPattern>hide.org.aspectj</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>cm.data.DatBoostrap</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
4

1 回答 1

0

您应该使用以下方法从其中一个工件中排除类:

<configuration>
 <filters>
  <filter>
   <artifact>junit:junit</artifact>
   <includes>
    <include>junit/framework/**</include>
    <include>org/junit/**</include>
   </includes>
   <excludes>
    <exclude>org/junit/experimental/**</exclude>
    <exclude>org/junit/runners/**</exclude>
   </excludes>
  </filter>
  <filter>
   <artifact>*:*</artifact>
   <excludes>
    <exclude>META-INF/*.SF</exclude>
    <exclude>META-INF/*.DSA</exclude>
    <exclude>META-INF/*.RSA</exclude>
   </excludes>
  </filter>
 </filters>
</configuration>
于 2015-04-20T20:05:34.287 回答