我正在尝试使用 Maven Shade 插件制作一个胖罐子,但遇到了麻烦。每次我运行阴影 jar 文件时,我都会收到此错误:
错误:无法初始化主类nz.ac.wgtn.swen301.assignment1.cli.StudentManagerUI 导致:java.lang.NoClassDefFoundError:org/apache/commons/cli/ParseException
我以前从未使用过 Maven Shade,所以我不太明白为什么这不包括 jar 中的所有依赖项。
这是我的pom.xml文件供参考:
4.0.0 nz.ac.wgtn.swen301 作业1 罐 1.0.0 swen301-作业1 http://maven.apache.org
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<!-- careful upgrading: newer versions seem to have been compiled with Java 17 !! -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.14.2.0</version>
</dependency>
<!-- to be used for the CLI -->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.5.0</version>
</dependency>
<!-- useful for several utilities, including data structures -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
</dependency>
<!-- local dependency to setup database -->
<dependency>
<groupId>nz.ac.wgtn.swen301</groupId>
<artifactId>studentdb</artifactId>
<version>1.3.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/studentdb-1.3.1.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.commons:commons-lang3</include>
<include>org.apache.commons:commons-cli</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>nz.ac.wgtn.swen301.assignment1.cli.StudentManagerUI</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我已经查看了 java.lang.NoClassDefFoundError 解决方案的多次迭代: 但到目前为止没有任何帮助。
非常感谢任何帮助!
提前非常感谢。