This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered" Watch "java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered" New topic

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

Vivek Doddaguni

Joined: Nov 25, 2012
Posts: 1
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];
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

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.
Prabu Dhanapal

Joined: Aug 12, 2011
Posts: 21
This will help you out.. Have a look..
subject: java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered
Similar Threads
programming problem
Unable to locate the element while executing TC as JUNIT but it is working fine in IDE
do we hava any core java API which simulates left mouse click and release?
selectOneMenu value using Selenium Webdriver+Java+Jsf