Results 1 to 1 of 1
  1. #1
    wildheart25c is offline Member
    Join Date
    Sep 2009
    Rep Power

    Default APACHE POI 2007 word documents

    As fas as I know, the following is all you need to print on a screen the contents of a 2007 ms word document.

    Java Code:
    package javaapplication9;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
    import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
    public class Main
        public static void main(String[] args)
            XWPFDocument doc;
                doc = new XWPFDocument(new FileInputStream("C:\\documents and settings\\x\\desktop\\1.docx"));
                XWPFWordExtractor wordxExtractor = new XWPFWordExtractor(doc);
            catch (IOException ex)
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    i added the following jar files to the library (setting classpath) which can be reached by right clicking on the project, selecting properties, then libraries, then add jar/folder:

    i got these jar files from just extract the contents to a folder. thts it. Easy.

    So why won't it work????? :(
    This is the exception I'm getting:
    Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.xwpf.usermodel.XWPFFactory.createDo cumentPart(
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument. java:186)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(
    at javaapplication9.Main.main(
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(
    at java.lang.reflect.Constructor.newInstance(Construc
    at org.apache.poi.xwpf.usermodel.XWPFFactory.createDo cumentPart(
    ... 4 more
    Caused by: java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/StylesDocument$Factory
    at org.apache.poi.xwpf.usermodel.XWPFStyles.onDocumen tRead(
    at org.apache.poi.xwpf.usermodel.XWPFStyles.<init>(XW
    ... 9 more
    Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.wordprocessingml.x2006. main.StylesDocument$Factory
    at$ 202)
    at Method)
    at ava:190)
    at java.lang.ClassLoader.loadClass( 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche
    at java.lang.ClassLoader.loadClass( 48)
    ... 11 more

    EDIT: Fixed it. I rarely look at the CAUSED BY clause because I always get my information from that first paragraph when it points to the line number in my code. I noticed CLASSDEFNOTFOUND. I've faced an error like this when I started this project. So I looked for org/openxmlformats/schemas/wordprocessingml/x2006/main/StylesDocument$Factory and learned that it was in the ool schemas folder. So now we have one more jar file to include on top of the list ia lready printed. This file is also find inside the zip you downloaded:

    Well hopefully when I edit my original project and add this, I won't have to bother you again. Maybe someone will learn from this. Good luck and thank you.
    Last edited by wildheart25c; 06-20-2011 at 06:03 AM.

Similar Threads

  1. Read Bookmarks from a word document using apache POI
    By anuskesh in forum Advanced Java
    Replies: 0
    Last Post: 07-28-2010, 04:36 AM
  2. Replies: 0
    Last Post: 11-15-2008, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts