2017-11-09 55 views
0

이 오류가 발생하는 이유를 모르겠습니다. 이 코드는 JXLS의 예제이며 Jar 파일은 여기에서 다운로드됩니다.간단한 JXLS/Apache POI 예제가 실패합니다.

오류 코드 :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:264) 
    at org.jxls.util.TransformerFactory.loadPoiTransformer(TransformerFactory.java:85) 
    at org.jxls.util.TransformerFactory.getTransformerClass(TransformerFactory.java:69) 
    at org.jxls.util.TransformerFactory.createTransformer(TransformerFactory.java:27) 
    at org.jxls.util.JxlsHelper.createTransformer(JxlsHelper.java:250) 
    at org.jxls.util.JxlsHelper.processTemplate(JxlsHelper.java:108) 
    at test_excel.ObjectCollectionDemo.main(ObjectCollectionDemo.java:32) 

Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
... 8 more 

참조 된 라이브러리 :

/slf4j-1.7.25/slf4j-api-1.7.25.jar
/slf4j-1.7.25/slf4j-jdk14 -1.7.25.jar
/jxls-2.4.1 2/DIST/jxls 리더-2.0.3.jar
/jxls-2.4.1 2/DIST/jxls-POI-1.0.13.jar
/xls-2.4.1 2/dist/jxls-jexcel-1.0.6.jar
/jxls-2.4.1 2/DIST/jxls-2.4.1.jar 홈페이지 코드

: 당신이 당신의 클래스 경로에 POI-3.XX.jar이 필요한 것처럼

package test_excel; 

import org.jxls.common.Context; 
import org.jxls.util.JxlsHelper; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Locale; 


public class ObjectCollectionDemo { 
    private static Logger logger = LoggerFactory.getLogger(ObjectCollectionDemo.class); 

    public static void main(String[] args) throws ParseException, IOException { 
     logger.info("Running Object Collection demo"); 
     List<Employee> employees = generateSampleEmployeeData(); 

     try(InputStream is = ObjectCollectionDemo.class.getResourceAsStream("object_collection_template.xls")) { 
      try (OutputStream os = new FileOutputStream("object_collection_output.xls")) { 
       Context context = new Context(); 
       context.putVar("employees", employees); 

       logger.info("OK so far..."); 

       JxlsHelper.getInstance().processTemplate(is, os, context); 
      } 
     } 
    } 

    public static List<Employee> generateSampleEmployeeData() throws ParseException { 
     List<Employee> employees = new ArrayList<Employee>(); 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd", Locale.US); 

     employees.add(new Employee("Elsa", dateFormat.parse("1970-Jul-10"), 1500, 0.15)); 
     employees.add(new Employee("Oleg", dateFormat.parse("1973-Apr-30"), 2300, 0.25)); 
     employees.add(new Employee("Neil", dateFormat.parse("1975-Oct-05"), 2500, 0.00)); 
     employees.add(new Employee("Maria", dateFormat.parse("1978-Jan-07"), 1700, 0.15)); 
     employees.add(new Employee("John", dateFormat.parse("1969-May-30"), 2800, 0.20)); 

     return employees; 
    } 
} 

답변