4

I use the maven-shade-plugin to build a project , However, I have encounter a problem I could not handle it.there are two jars almost have the same class and the path is same,aspectjweaver.jar and aspectjrt.jar , when package the jar ,I get the warning "duplicate class have exist in ....". I tried to use the "relocation" property to relocate the class, but the question is , How can I recongnize the class in the two jars? Next is part of my 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>

1 Answers1

0

you should just exclude the classes from one of the artifacts using some thing like this:

<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>
igreenfield
  • 1,618
  • 19
  • 36