<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>hui</groupId> <artifactId>TestWithMaven</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>TestWithMaven</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.13</version> </dependency> <dependency> <groupId>org.apache.ibatis</groupId> <artifactId>ibatis-core</artifactId> <version>3.0</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> <version>1.3</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.2.2.RELEASE</version> </dependency> <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.6.12</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> </dependencies> </project>
ClassNotFoundException: jxl.write.WriteException.java
同理:.測試poi導出excel時,main方法測時正常,可是佈署寫成Servlet形式,佈署到Tomcat 8上就報錯:mysql
ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFAnchorspring
顯然依賴裏有的,解決方法是:sql
將依賴的jar文件jxl-2.6.12.jar、poi-3.14.jar 拷貝到Tomcat的安裝目錄下的lib目錄裏,如:D:\apache-tomcat-8.0.35\lib,而後重啓便可。apache
致使這一緣由的方法,是maven依賴會做爲entry,即未自動加入到WEB-INF/lib目錄下,這時咱們須要:api
右鍵項目-->Properties-->Deployment Assembly,若是展開 的頁面中沒有Maven dependencies,這時咱們點擊右上角的Add-->Java Build Path Entries-->Maven Dependencies-->finish。tomcat
這時maven依賴即自動加入到WEB-INF/lib目錄下,雖然你看不到。而後重啓服務器,即正常。服務器