Maven 程序集:NoClassDefFoundError
Maven Assembly : NoClassDefFoundError
我正在使用 maven 程序集插件构建单个 JAR,但在 运行 以下
之后出现此错误
java -jar target/pdfbox-printing-1.0-SNAPSHOT-jar-with-dependencies.jar
错误是
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
这就是我编译 JAR 的方式
mvn clean compile assembly:single
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.printing</groupId>
<artifactId>pdfbox-printing</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>pdfbox-printing</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.company.printing.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
我实际上正在尝试构建一个使用 apache pdfbox 的项目。我认为 Maven 程序集插件会将所有依赖项捆绑在一个 JAR 中,但如果它是真的,为什么我会收到此错误。
如错误所示,org/bouncycastle/jce/provider/BouncyCastleProvider
有 NoClassDefFoundError
,在这种情况下,您可以通过在 <dependencies>
中添加以下内容来使用 Maven 库:
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk16 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.54</version>
</dependency>
这将帮助您导入包并使用代码中所需的 Class。
可能需要更多依赖项,请参阅 here。
我正在使用 maven 程序集插件构建单个 JAR,但在 运行 以下
之后出现此错误java -jar target/pdfbox-printing-1.0-SNAPSHOT-jar-with-dependencies.jar
错误是
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
这就是我编译 JAR 的方式
mvn clean compile assembly:single
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.printing</groupId>
<artifactId>pdfbox-printing</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>pdfbox-printing</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.company.printing.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
我实际上正在尝试构建一个使用 apache pdfbox 的项目。我认为 Maven 程序集插件会将所有依赖项捆绑在一个 JAR 中,但如果它是真的,为什么我会收到此错误。
如错误所示,org/bouncycastle/jce/provider/BouncyCastleProvider
有 NoClassDefFoundError
,在这种情况下,您可以通过在 <dependencies>
中添加以下内容来使用 Maven 库:
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk16 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.54</version>
</dependency>
这将帮助您导入包并使用代码中所需的 Class。
可能需要更多依赖项,请参阅 here。