How to avoid java.lang.NoClassDefFoundError

I have a code for adding the texts to existing .doc file and it'll save that as another name by using apache POI.

The following is the code I have tried so far

import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFFooter;
import org.apache.poi.xwpf.usermodel.XWPFTable;

public class FooterTableWriting {

    public static void main(String args[])
        String path="D:\\vignesh\\AgileDocTemplate.doc";
        String attch="D:\\Attach.doc";
        String comment="good";
        String stat="ready";
        String coaddr="xyz";
        String cmail="";
        String sub="comp";
        String title="Globematics";
        String cat="General";
        setFooter(path, attch, comment, stat, coaddr, cmail, sub, title, cat);
    private static  void setFooter(String docTemplatePath,String attachmentPath,String comments,String status,String coAddress,String coEmail,String subject,String title,String catagory)

                    InputStream input = new FileInputStream(new File(docTemplatePath));
                    XWPFDocument document=new XWPFDocument(input);
                    XWPFHeaderFooterPolicy headerPolicy =new XWPFHeaderFooterPolicy(document);
                    XWPFFooter footer = headerPolicy.getDefaultFooter();
                    XWPFTable[] table = footer.getTables();

                    for (XWPFTable xwpfTable : table)


                  File f=new File (attachmentPath.substring(0,attachmentPath.lastIndexOf('\\')));


                  FileOutputStream out = new FileOutputStream(new File(attachmentPath));

                  System.out.println("Attachment Created!");

          catch(Exception e)



The following is what I got

    org.apache.poi.POIXMLException: org.apache.xmlbeans.XmlException: error: The document is not a document@ document element mismatch got themeManager@
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(
    at org.apache.poi.POIXMLDocument.load(
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(
Caused by: org.apache.xmlbeans.XmlException: error: The document is not a document@ document element mismatch got themeManager@
    at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(
    at org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(
    ... 4 more

I have added all the jar files corresponding to this but still I can't find the solution.I'm new to this apache poi so please help me with some explanations and examples. Thanks

Copied from my comment done to the question:

Looks like you need poi-ooxml-schemas.jar that comes in the Apache POI distribution. Just adding a single jar doesn't mean that you have all the classes of the framework.

After solving the problem based on my comment (or another people answers), you have this new Exception

org.apache.xmlbeans.XmlException: error: The document is not a document@ document element mismatch got themeManager@

Reading Apache POI - HWPF - Java API to Handle Microsoft Word Files, it looks like you're using the wrong class to handle 2003- word documents: HWPF is the name of our port of the Microsoft Word 97(-2007) file format to pure Java ... The partner to HWPF for the new Word 2007 .docx format is XWPF.. This means that you need HWPFDocument class to handle the document or change your document from Word 2003- to Word 2007+.

IMO I find Apache POI as a good solution to handling Excel files, but I would look another options to handling Word documents. Check this question to get more related info.

How to solve java.lang.NoClassDefFoundError?, After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets  NoClassDefFoundError can often be observed when you forget to add JAR file(s) containing Java classes referenced by your Java or Java EE application. This type of problem is normally not hard to

This is the dependency hierarchy for poi-ooxml-3.9.jar.

Which means any of them can be used at runtime even if they aren't used at compile-time.

Make sure you have all the jars in the classpath of your project.

How to Resolve java.lang.NoClassDefFoundError: How to resolve , NoClassDefFoundErrorSimulator java.lang. did prevent the current class loader to locate this referencing Java class at runtime leading to  My classpath is correct, which most people suggested. The problem could not so simple, I am sure what is the "stack:" mean in the errors log file.

Add this dependency on your config file:



System couldn’t find the 


Please add the library to your classpath.

java.lang.NoClassDefFoundError, Interested to learn more about Java Errors? Then check out our detailed example on How to solve No Class Def Found Error! This error is  My application is a platform w/GUI for users to run their sub-programs. Before the user decides that they'd like to "install" their program into my application, I want to let them know that they probably forgot to add some class files (in addition to some of the other checks that I run).

The class org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument.Factory is located in the jar ooxml-schemas-1.0.jar which can be downloaded here

Java Exception Handling - NoClassDefFoundError, NoClassDefFoundError in Java, including code that shows how to prevent you from accidentally getting in a situation where a java.lang. A close look into the java.lang.NoClassDefFoundError in Java, including code that shows how project structure impacts compilation and execution.

You're getting that error because you don't have the proper dependency for the XWPFDocument. ooxml-schemas requires xmlbeans, and ooxml requires poi and ooxml-schemas, etc...

Check here:

Java- Exception in thread "main" java.lang.NoClassDefFoundError , The Exception in thread "main" java.lang.NoClassDefFoundError is a common error in Java which occurs if a ClassLoader is not able to find a particular class in​  Click on Project -> Properties -> Java Build Path (on left panel) -> select Libraries Tab -> click on Add External JARs and import the jar. So in order to avoid the above problem I add the above jar to Deployment Assembly as well.

java.lang.NoClassDefFoundError, java.lang.NoClassDefFoundError is runtime error thrown when a required class is not found in the classpath and hence JVM is unable to load it into memory. How to avoid NoClassDefError?. Java Forums on Bytes. Need help? Post your question and get tips & solutions from a community of 447,533 IT Pros & Developers.

ClassNotFoundException Vs NoClassDefFoundError in Java , java.lang.ClassNotFoundException: GeeksForGeeks. NoClassDefFoundError ClassNotFoundException occurs when classpath is does not get updated with  I&#39;m not sure if this is the right venue to post this question, but though I would start here before going to StackOverflow. I am attempting to use JTransforms to compute a DoubleFFT_1D. The ful

How to solve java.lang.NoClassDefFoundError in java, How to avoid NoClassDefFoundError in java? Ensure that static initialization block of classes or static variables  Search Data Center. Tech giants aim supercomputers, clouds at finding a COVID-19 cure. The new COVID-19 HPC consortium comprised of tech giants, national labs and academia are using supercomputers and clouds to speed

  • Looks like you need poi-ooxml-schemas.jar that comes in the Apache POI distribution. Just adding a single jar doesn't mean that you have all the classes of the framework.
  • Are you using Eclipse?
  • yes....I'm using eclipse
  • How to avoid it? As usual, make sure, all required classes are on the classpath ;)
  • lol @EJP if you actually read the comments the op said that he fixed the first thing by adding an extra jar and now he's getting a different error. Then he said he'd update the error. I wish I could downvote your comment.
  • I have the following structure.But I have poi-ooxml 3.8 and poi-ooxml-schemas 3.8
  • Having different versions should not cause any issue.
  • As per this Apache POI FAQ entry that is entirely to be expected - it is not supported to mix POI jars from different versions