0

我有一个写出电子表格的 Tomcat 应用程序,它使用以下 JAR 文件:

  • poi-3.16.jar
  • poi-ooxml-3.16.jar
  • poi-ooxml-schemas-3.16.jar

我看到有一个 4.0.1 版本的 poi,在查看https://poi.apache.org/components/时,我认为我已经设置了先决条件,但是运行时出现异常:

25-Mar-2019 22:33:37.117 SEVERE [http-nio-8181-exec-10] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [xxx.ApplicationConfig] in context with path [/DataLoaderREST] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.ExceptionInInitializerError] with root cause
 java.lang.RuntimeException: Uncompilable source code - cannot find symbol
  symbol:   class POIXMLDocument
  location: package org.apache.poi

更新:

显然,当我构建出现上述错误的 .WAR 文件时,NetBeans 似乎找到了旧的 3.16 jar 文件并编译了我的代码,但我在服务器上没有 3.16 jar 文件。现在我已经在 NetBeans 中进行了清理,我无法在 NetBeans 中进行编译。

错误:

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ DataModules ---
Compiling 44 source files to C:\xxx\xxx\10 Software\Java\LoaderFramework\DataModules\target\classes
-------------------------------------------------------------
COMPILATION ERROR : 
-------------------------------------------------------------
com/xxx/billing/loader/parser/ExcelParser.java:[36,21] error: cannot find symbol

ExcelParser.jara 第 36 行是:

import org.apache.poi.POIXMLDocument;

这是我的 pom.xml,引用了 4.0.1 jar:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xx.billing</groupId>
    <artifactId>DataModules</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

        <dependencies>
               <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
        </dependency>

        <!-- POI artifacts See https://poi.apache.org/components/  -->
        <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.2</version>
        </dependency>
        <dependency>
          <groupId>commons-codec</groupId>
          <artifactId>commons-codec</artifactId>
          <version>1.11</version>
        </dependency>
        <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-collections4</artifactId>
                <version>4.2</version>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-math3</artifactId>
          <version>3.6.1</version>
        </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
          <!-- type>bundle</type -->
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-compress</artifactId>
          <version>1.18</version>
        </dependency>        
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.0.1</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>com.xx.billing</groupId>
            <artifactId>DataLoderShared</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>     

        <dependency>
            <groupId>com.rabbitmq</groupId>
            <artifactId>amqp-client</artifactId>
            <version>3.5.4</version>
            <scope>compile</scope>
        </dependency>   
        <dependency>
            <groupId>com.univocity</groupId>
            <artifactId>univocity-parsers</artifactId>
            <version>1.5.6</version>
            <scope>compile</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.ibm.icu</groupId>
            <artifactId>icu4j</artifactId>
            <version>55.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

我已经检查了我的 NetBeans .m2 存储库,并且在C:\Users\mstewart\.m2\repository\org\apache\poi\poi\andpoi\ooxml和 and中有 3.16 和 4.0.1 目录poi\ooxml-schemas

4

1 回答 1

1

我盯着编译器错误

import org.apache.poi.POIXMLDocument;

好几天了,只是注意到它缺少ooxml包裹的一部分;将其更改为

import org.apache.poi.ooxml.POIXMLDocument;

一切都很好。感谢阿克塞尔的链接;这帮助我最终找到了问题。

于 2019-03-26T19:29:36.853 回答