maven install发出警告,生成可运行的jar



我们正在构建一个基于maven的项目。现在我正在尝试使用shade插件来生成一个可运行的jar文件。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer   implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.myCompany.mainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
  <id>apache maven</id>
  <url>http://repo1.maven.org/maven2/org/apache/maven/plugins</url>
</pluginRepository>
</pluginRepositories>

当我运行maven build时,它给出了许多警告:[警告]我们在C:Usersmaven.repocompanyorgslf4jslf4j-nop1.6.2slf4j-nop-1.6.2.jar

中有一个重复的org/slf4j/imp/staticmdcbind .class

似乎每个依赖项都得到了重复。有人能给我一些建议吗?非常感谢大家,祝大家感恩节快乐。

使用maven dependency:tree命令可以打印并检查所有日志依赖项,可能其中一些包含重复的类,例如在本例中http://maven.40175.n5.nabble.com/Duplicate-class-warnings-when-using-shade-plugin-td121854.html然后使用exclude标签从它们中删除冗余排除单个依赖项的所有传递依赖

我还建议使用maven-assembly-plugin,它将jar与依赖关系附加为可配置分类器下的附加工件,而不是替换原始工件(如在您的配置中):

            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.myCompany.mainClass</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>

最新更新