我有一个Tomcat应用程序写出电子表格,它使用以下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\
和poi\ooxml
以及poi\ooxml-schemas
中都有3.16和4.0.1目录
我盯着编译错误
import org.apache.poi.POIXMLDocument;
好几天了,只是注意到它丢失了包装的ooxml
部分;改成了
import org.apache.poi.ooxml.POIXMLDocument;
一切都很好。感谢Axel的链接;这帮助我最终找到了问题。