猿问

Java - NoClassDefFoundError XSSFWorkbook

我创建 CSV 到 XLSX 应用程序 -我的第一个问题

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook

        at com.test.csv2xlsx.Csv2Xlsx.<init>(Csv2Xlsx.java:35)

        at com.test.csv2xlsx.Csv2Xlsx.main(Csv2Xlsx.java:49)

Caused by: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook

        at java.net.URLClassLoader.findClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        ... 2 more

我阅读了有关此错误的所有文章,但我已经拥有所有依赖项


<dependencies>

        <dependency>

            <groupId>org.apache.poi</groupId>

            <artifactId>poi-ooxml</artifactId>

            <version>4.1.0</version>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

            <version>4.12</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.apache.poi</groupId>

            <artifactId>poi</artifactId>

            <version>4.1.0</version>

        </dependency>

        <dependency>

            <groupId>org.hamcrest</groupId>

            <artifactId>hamcrest-core</artifactId>

            <version>1.3</version>

        </dependency>

        <dependency>

            <groupId>org.apache.xmlbeans</groupId>

            <artifactId>xmlbeans</artifactId>

            <version>3.1.0</version>

        </dependency>

        <dependency>

            <groupId>org.apache.poi</groupId>

            <artifactId>poi-ooxml-schemas</artifactId>

            <version>4.1.0</version>

        </dependency>

        <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-collections4</artifactId>

            <version>4.3</version>

        </dependency>

    </dependencies>

现在我不确定问题出在哪里

慕尼黑的夜晚无繁华
浏览 333回答 1
1回答

慕的地8271018

这是一个很常见的问题。您的项目的依赖项未包含在您执行的 jar 中,导致NoClassDefFoundError.要解决此问题,请将其添加到plugins您的部分pom.xml:<plugin>&nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; <artifactId>maven-assembly-plugin</artifactId>&nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>package</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>single</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <archive>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <manifest>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <mainClass>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; com.mypackage.Main&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </mainClass>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </manifest>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </archive>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <descriptorRefs>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <descriptorRef>jar-with-dependencies</descriptorRef>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </descriptorRefs>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; </executions></plugin>然后执行mvn clean package,当在目标目录中完成时,您将找到一个jar_name-jar-with-dependencies.jar包含所有必需依赖项的可执行文件。最后干脆run java -jar jar_name-jar-with-dependencies.jar。
随时随地看视频慕课网APP

相关分类

Java
我要回答