Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the following error while trying to open an excel file using Junit4 selenium web driver in Eclipse. Code and error is pasted below. I am new to Java. Please help. Thank you.

Error message in ecliplse
java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(
at org.apache.poi.openxml4j.opc.Package.<init>(
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(
at clsUSPSMatch_WebDeriver.xlRead_TC(
at clsUSPSMatch_WebDeriver.setUp(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.internal.runners.statements.RunAfters.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(


import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;

//import statement for excel files - VD Nov/224/2012
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.*;
import* ;
import org.apache.poi.xssf.usermodel.*;

import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class clsUSPSMatch_WebDeriver {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();

int xRows_Inp, xCols_Inp;
String xData_Inp[][];

public void setUp() throws Exception {

System.out.println("Step1- Starting the browser --> Reached");
driver = new InternetExplorerDriver();
//driver = new FirefoxDriver();
baseUrl = "";

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

//Procedure to read from an excel file -vd
xlRead_TC("C:\\USPS\\USPSInput.xlsx", 0);


public void testUntitled() throws Exception {

//Declare Global Input Variables -Vivek D
String vRecord, vAddrInp, vCityInp, vZipInp; //

//int xRows_Inp, xCols_Inp;
//String xData_Inp[][];

//Declare Global Output Variables -Vivek D
String vAddr1, vCity1, vAddr2, vCity2,vAddr3, vCity3; //
String vAddr1Pdm, vCity1Pdm, vAddr2Pdm, vCity2Pdm, vAddr3Pdm, vCity3Pdm;

int counter;

// open | |
System.out.println("Step2- Opening the browser --> Reached");
// assertTitle | USPS - The United States Postal Service (U.S. Postal Service) |
assertEquals("USPS - The United States Postal Service (U.S. Postal Service)", driver.getTitle());

// click | id=qt-zip-link |

//For loop to go tjrough the logic 3 times
for (counter = 0; counter < 2; counter ++){
System.out.println("Counter valie is :" + counter);
//driver.findElement(By.linkText("Look Up A ZIP Code")).click();

System.out.println("Step3- clicked the look up a zip code button --> Reached");

// type | id=qz-tAddress | 1000 aviara parkway
driver.findElement("qz-tAddress")).sendKeys("1000 aviara parkway");
// type | id=qz-tCity | carlsbad
// click | |
// click | link=CA - California |
driver.findElement(By.linkText("CA - California")).click();
// type | id=qz-tZip | 92009
// click | id=dofind_btn |
System.out.println("Step4- clicked the find addresses button --> Reached");

//copy the results to output variables
System.out.println("Step5- copy the addresses to output variables --> Reached");

//writing the results to variables - first set
//Initialize Global Output Variables - Vivek D
vAddr1 = ""; vCity1=""; vAddr2=""; vCity2=""; vAddr3=""; vCity3=""; //
vAddr1Pdm = ""; vCity1Pdm = ""; vAddr2Pdm = ""; vCity2Pdm = ""; vAddr3Pdm = ""; vCity3Pdm = ""; //

System.out.println(" The retrieved address1 before: " + vAddr1);
vAddr1 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[3]")).getText();
//vAddr1 = selenium.getText("xpath=html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[3]");
System.out.println(" The retrieved address1 after: " + vAddr1);

System.out.println(" The retrieved city1 before: " + vCity1);
vCity1 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[4]")).getText();
System.out.println(" The retrieved city1 after: " + vCity1);

//writing the results to variables - second set
System.out.println(" The retrieved address2 before: " + vAddr2);
vAddr2 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[2]/div[3]")).getText();
System.out.println(" The retrieved address2 after: " + vAddr2);

System.out.println(" The retrieved city2 before: " + vCity2);
vCity2 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[2]/div[4]")).getText();
System.out.println(" The retrieved city2 after: " + vCity2);

//writing the results to variables - third set
System.out.println(" The retrieved address3 before" + vAddr3);
vAddr3 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[3]/div[3]")).getText();
System.out.println(" The retrieved address3 after" + vAddr2);

System.out.println(" The retrieved city3 before" + vCity3);
vCity3 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[3]/div[4]")).getText();
System.out.println(" The retrieved city3 after" + vCity3);

//Close the look up window
// click | id=qtmodal-box-closeModal |
} // end for loop - vivek D

public void tearDown() throws Exception {
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {

private boolean isElementPresent(By by) {
try {
return true;
} catch (NoSuchElementException e) {
return false;

public void xlRead_TC(String sPath, int sSheet) throws Exception{
//XSSFWorkbook wb = new XSSFWorkbook();
//XSSFWorkbook workBook = new XSSFWorkbook(destDir);
//Workbook wb = new XSSFWorkbook();
//FileOutputStream f = new FileOutputStream("C:\\USPS\\USPSInput.xlsx",true);
//File inputWorkbook = new File("C:\\USPS\\USPSInput.xlsx");
//Workbook w;
//w = Workbook.getWorkbook(inputWorkbook);

//Workbook book = Workbook.createWorkbook(f);

System.out.println("Step 1B - Opening excel files Reached");
File myxl = new File(sPath);
FileInputStream myStream = new FileInputStream(myxl);
//Workbook w;
//w = Workbook.getWorkbook(myStream);

XSSFWorkbook myWB = new XSSFWorkbook(myStream);
//XSSFSheet mySheet = myWB.getSheetAt(sSheet); // Referring to 1st sheet

//xRows_Inp = mySheet.getLastRowNum()+1;
//xCols_Inp = mySheet.getRow(0).getLastCellNum();
System.out.println("Rows are " + xRows_Inp);
System.out.println("Cols are " + xCols_Inp);

//Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };

//xRows_TC = mySheet.getLastRowNum()+1;
//xCols_TC = mySheet.getRow(0).getLastCellNum();
//System.out.println("Rows are " + xRows_TC);
//System.out.println("Cols are " + xCols_TC);
//xData_TC = new String[xRows_TC][xCols_TC];
Posts: 26963
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because POI needs to have the DOM4J jar in the classpath. You'll find it in your POI download in the ooxml-lib folder.
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This will help you out.. Have a look..
    Bookmark Topic Watch Topic
  • New Topic