2012-09-17 3 views
0

나는 하나의 클래스를 가지고 있는데, 그 클래스는 엑셀 시트를 만든다. 나는 classpath에 poi-3.2.jar를 추가했다. Eclipse3.7에서 작업하고 있습니다.
WindowTester Pro를 사용하여 작업대 작업을 기록하여 테스트 사례를 생성했습니다. 생성 된 테스트 케이스를 편집하여 그 안에 엑셀 시트를 작성하여 테스트 결과를 작성하려고했습니다.

일반 자바 프로그램과 동일한 API를 (플러그인 자체 내에서) 사용하면 오류없이 Excel 파일을 생성 할 수 있습니다. 내가 lib 폴더에 필요한 jar 파일을 추가하고 빌드 경로에 추가 한NoClassDefFoundError를 TestCases로만 가져 오기

java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook 

: 나는 테스트 케이스에서 만들 때 하지만, 나는 다음과 같은 오류를 얻고있다. 왜 정상적인 자바 프로그램에서 작동하지만 WindowTester에서 작동하지 않는 것은 테스트 케이스를 생성했습니다.

import com.windowtester.runtime.IUIContext; 
import com.windowtester.runtime.swt.UITestCaseSWT; 
import com.windowtester.runtime.swt.locator.eclipse.WorkbenchLocator; 

public class Configuration extends UITestCaseSWT { 

/* 
* @see junit.framework.TestCase#setUp() 
*/ 
protected void setUp() throws Exception { 
    super.setUp(); 
    IUIContext ui = getUI(); 
    try { 
     CreateExcelFile file = new CreateExcelFile(); 
     file.CreateExcel(); 
    } catch (Throwable e) { 
     System.out.println("***** Exception catched.. *****"); 
     // fail("Configuration failed"); 
     e.printStackTrace(); 
    } 
    ui.ensureThat(new WorkbenchLocator().hasFocus()); 
} 

/** 
* Main test method. 
*/ 
public void testConfiguration() throws Exception { 

    //Test code 
    } 

@Override 
protected void tearDown() throws Exception { 
    super.tearDown(); 
    // .... 
} 

} 


public class CreateExcelFile { 
HSSFRow row; 
HSSFRichTextString string; 

public void CreateExcel() { 
    try { 
     String filename = "E:/hello.xls"; 
     HSSFWorkbook hwb = new HSSFWorkbook(); 
     HSSFSheet sheet = hwb.createSheet("new sheet"); 

     HSSFRow rowhead = sheet.createRow((short) 0); 
     string = new HSSFRichTextString("TC_Name"); 
     rowhead.createCell((int) 0).setCellValue(string); 
     string = new HSSFRichTextString("Result"); 
     rowhead.createCell((int) 1).setCellValue(string); 

     for (int i = 0; i <= 10; i++) { 
      row = sheet.createRow((short) i); 
      string = new HSSFRichTextString("TC_Name" + i); 
      row.createCell((int) 0).setCellValue(string); 
      if (i % 2 == 0) { 
       row.createCell((int) 1).setCellValue(true); 
      } else { 
       row.createCell((int) 1).setCellValue(false); 
      } 
     } 
     FileOutputStream fileOut = new FileOutputStream(filename); 
     hwb.write(fileOut); 

     fileOut.close(); 
     System.out.println("Your excel file has been generated!"); 
    } catch (Exception ex) { 
     System.out.println(ex); 
    } 
} 

}

이 사람이 나를 도울 수 :

여기 내 코드입니다.

+0

Window-tester 일은 잘 모릅니다.하지만 제 생각에 이클립스 클래스 패스와 다른 클래스 패스를 사용하고 있습니다. jar가 들어있는 빌드 경로는 Window-tester에서 사용한 경로와 동일하지 않습니다. – Bhaskar

+0

WindowTester가 내 Eclipse와 통합되었습니다.이 플러그인을 설치했습니다. – CharanTej

+0

예외가 발생하는 곳의 코드를 게시 할 수 있습니까? –

답변

0

문제가 발생했습니다. 그것 때문에 런타임 클래스 경로. 매니 페스트 편집기에서 매니페스트 .MF를 열어 솔루션을 발견했습니다. 그런 다음 런타임 탭의 클래스 경로 섹션에 JAR을 추가했습니다.
오류없이 작동합니다.

관련 문제