【问题标题】:classnotfoundexeption : org.apache.poi.ss.usermodel.rowclassnotfoundexeption : org.apache.poi.ss.usermodel.row
【发布时间】:2015-04-13 08:13:25
【问题描述】:

我是 Java 新手,刚刚使用 Netbeans、Maven 和 Apache POI 开发了一个应用程序。

应用程序从 excel 文件中读取输入并在不同的 excel 文件中生成输出。

当我运行应用程序 Netbeans 时一切正常,但是当我尝试运行生成的 jar 文件时,出现以下错误

classnotfoundexeption : org.apache.poi.ss.usermodel.row

【问题讨论】:

  • 在运行应用程序时,您必须在 classpath 中包含库。
  • 我的问题出在哪里。我不知道该怎么做

标签: java excel apache maven netbeans


【解决方案1】:

我已经在我的 POM.xml 中声明了 poi 和 poi-ooxml 依赖项,因此该应用程序在 netbeans 中运行良好。问题是生成的 .jar 文件没有运行

【讨论】:

    【解决方案2】:

    您使用 Maven,因此您需要在依赖项中添加所需的库。

    像这样:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.11</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.11</version>
    </dependency>
    

    你会用这个: org.apache.poi.ss.usermodel.Row

    如果你想将你的依赖项放入你的 jar 文件中,你需要像这样强制构建:

    <!-- Add Shade plugin to include Apache POI dependencies into jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>org.apache.poi:poi-ooxml-schemas</include>
                                    <include>org.apache.poi:poi-ooxml</include>
                                    <include>org.apache.poi:poi</include>
                                    <include>org.apache.xmlbeans:xmlbeans</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

    • 我的 pom.xml 中有这些依赖项,因此该应用程序可以在 Netbeans 中运行。是生成的jar文件不起作用
    猜你喜欢
    • 2018-02-27
    • 1970-01-01
    • 2014-04-09
    相关资源
    最近更新 更多