Results 1 to 12 of 12
  1. #1
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default APACHE POI 2007 word documents

    I need to generate the word document dynamically using java code, included the necessary jar files, No compliation issue, but During run time am getting this error: Could not initialize class org.openxmlformats.schemas.wordprocessingml.x2006. main.CTDocume .using all these jar files: POI-3.6.jar, POI_3.9.jar, Poi-ooxml-3.5,Poi-ooxml-3.6,Poi-ooxml-3.7,Poi-ooxml-3.9,Poi-ooxml-schemas-3.6,Poi-ooxml-schemas-3.9.jar. using the XWPFdocument class. when my cursor get into that line XWPFDocument doc = new XWPFDocument();
    getting the above error.

    Any help is much appreciated....

    Thanks,

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: APACHE POI 2007 word documents

    Please don't resurrect old threads to ask your question.
    Threads are free...

    Can you post the full exception, including stack trace?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default Re: APACHE POI 2007 word documents

    Quote Originally Posted by Tolls View Post
    Please don't resurrect old threads to ask your question.
    Threads are free...

    Can you post the full exception, including stack trace?
    Hi Toll,

    Please find the below code and exception trace:

    XWPFDocument document = new XWPFDocument();

    // New 2x2 table
    XWPFTable tableOne = document.createTable();
    XWPFTableRow tableOneRowOne = tableOne.getRow(0);
    tableOneRowOne.getCell(0).setText("Hello");
    tableOneRowOne.addNewTableCell().setText("World");

    XWPFTableRow tableOneRowTwo = tableOne.createRow();
    tableOneRowTwo.getCell(0).setText("This is");
    tableOneRowTwo.getCell(1).setText("a table");

    //Add a break between the tables
    document.createParagraph().createRun().addBreak();

    // New 3x3 table
    XWPFTable tableTwo = document.createTable();
    XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
    tableTwoRowOne.getCell(0).setText("col one, row one");
    tableTwoRowOne.addNewTableCell().setText("col two, row one");
    tableTwoRowOne.addNewTableCell().setText("col three, row one");

    XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
    tableTwoRowTwo.getCell(0).setText("col one, row two");
    tableTwoRowTwo.getCell(1).setText("col two, row two");
    tableTwoRowTwo.getCell(2).setText("col three, row two");

    XWPFTableRow tableTwoRowThree = tableTwo.createRow();
    tableTwoRowThree.getCell(0).setText("col one, row three");
    tableTwoRowThree.getCell(1).setText("col two, row three");
    tableTwoRowThree.getCell(2).setText("col three, row three");

    FileOutputStream outStream = null;


    try {
    document.write(outStream);
    outStream.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Exception:

    Could not initialize class org.openxmlformats.schemas.wordprocessingml.x2006. main.CTDocument1

    Not getting the exception in my console, So When I inspect the exception InvocationTarget Exception->NoClassDefFounderror->Could not initialize class org.openxmlformats.schemas.wordprocessingml.x2006. main.CTDocument1

    Console Exception is like below:
    WARN - RequestProcessor.processException(538) | Unhandled Exception thrown: class java.lang.reflect.InvocationTargetException
    ERROR - IAMLogger.severe(72) | Severe Exception : javax.servlet.ServletException in IAMFilter - doFilter
    Last edited by vimalforum; 07-31-2014 at 11:18 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: APACHE POI 2007 word documents

    That is not a full exception with stack trace.

    You also need to post code in [ code] tags [ /code] so it retains its formatting.
    And probably point out which line of the given code is the source of the exception.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: APACHE POI 2007 word documents

    That is the exception -message-, not the exception. Tolls asked for the full exception, including stacktrace.

    Most likely somewhere in there is a "ClassNotFound", but at this point it is only guesswork because you are hiding information.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default Re: APACHE POI 2007 word documents

    Tol,

    Below is my Code

    XWPFDocument document = new XWPFDocument();

    // New 2x2 table
    XWPFTable tableOne = document.createTable();
    XWPFTableRow tableOneRowOne = tableOne.getRow(0);
    tableOneRowOne.getCell(0).setText("Hello");
    tableOneRowOne.addNewTableCell().setText("World");

    XWPFTableRow tableOneRowTwo = tableOne.createRow();
    tableOneRowTwo.getCell(0).setText("This is");
    tableOneRowTwo.getCell(1).setText("a table");

    //Add a break between the tables
    document.createParagraph().createRun().addBreak();

    // New 3x3 table
    XWPFTable tableTwo = document.createTable();
    XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
    tableTwoRowOne.getCell(0).setText("col one, row one");
    tableTwoRowOne.addNewTableCell().setText("col two, row one");
    tableTwoRowOne.addNewTableCell().setText("col three, row one");

    XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
    tableTwoRowTwo.getCell(0).setText("col one, row two");
    tableTwoRowTwo.getCell(1).setText("col two, row two");
    tableTwoRowTwo.getCell(2).setText("col three, row two");

    XWPFTableRow tableTwoRowThree = tableTwo.createRow();
    tableTwoRowThree.getCell(0).setText("col one, row three");
    tableTwoRowThree.getCell(1).setText("col two, row three");
    tableTwoRowThree.getCell(2).setText("col three, row three");

    FileOutputStream outStream = null;


    try {
    document.write(outStream);
    outStream.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    getting the exception in line
    XWPFDocument document = new XWPFDocument();

    using all these jar files
    using all these jar files: POI-3.6.jar, POI_3.9.jar, Poi-ooxml-3.5,Poi-ooxml-3.6,Poi-ooxml-3.7,Poi-ooxml-3.9,Poi-ooxml-schemas-3.6,Poi-ooxml-schemas-3.9.jar

  7. #7
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default Re: APACHE POI 2007 word documents

    Hi Gimbal,

    Not getting any stacktrace in my console, So that am not able to post it here.

    When I inspect the exception in Catch,

    InvocationTarget Exception->NoClassDefFounderror->Could not initialize class org.openxmlformats.schemas.wordprocessingml.x2006. main.CTDocument1

    getting like the above one.

    Thanks,

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: APACHE POI 2007 word documents

    Now that I look at the list of jar files you say you are using, you have multiple versions of POI in there:
    POI-3.6.jar, POI_3.9.jar
    and ooxml
    Poi-ooxml-3.5,Poi-ooxml-3.6,Poi-ooxml-3.7,Poi-ooxml-3.9

    Pick one version and stick with that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default Re: APACHE POI 2007 word documents

    Quote Originally Posted by Tolls View Post
    Now that I look at the list of jar files you say you are using, you have multiple versions of POI in there:
    POI-3.6.jar, POI_3.9.jar
    and ooxml
    Poi-ooxml-3.5,Poi-ooxml-3.6,Poi-ooxml-3.7,Poi-ooxml-3.9

    Pick one version and stick with that.
    Hi Tolls,

    I have removed all the jars and have only in the below jar files,

    Poi.jar, Poi-3.9.jar,Poi-ooxml3.9.jar,poi-ooxml-schemas-3.9.jar and ooxml-schemas-1.1.jar

    this case am getting the below errorr:

    java.lang.ExceptionInInitializerError->Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?

    Can you please let me know what are all the jar files needs to be added for XWPFDocument class?

    My requirement is to generate the dynamic Word document(.docx) using java code.

    Thanks,

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: APACHE POI 2007 word documents

    How are you deploying this? I see mentions of a RequestProcessor, a ServletException and a filter, so this is in a web application? Assuming so, did you check the actual server logs which may hold more complete error information? And how and where are you deploying the jar dependencies?

    You keep referring to "my console", I assume that is the console in your IDE. That's okay for development purposes, but you should always check the server logs before you claim that "there is no more".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    vimalforum is offline Member
    Join Date
    Jul 2014
    Posts
    6
    Rep Power
    0

    Default Re: APACHE POI 2007 word documents

    Hi gimbal,

    Am getting these errors are in my local machine, Even if i checked log file also displaying the following error:

    WARN (RequestProcessor.java:538) - Unhandled Exception thrown: class java.lang.reflect.InvocationTargetException
    (IAMLogger.java:72) - Severe Exception : javax.servlet.ServletException in IAMFilter - doFilter
    when i inspect the exception in my Eclipse got the below:
    java.lang.ExceptionInInitializerError->Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?

    Yes, this is a web appliation, Deployed all the jar files in my Eclipse Buildpath.
    Am using the below jar files also.
    Xbeans2.2.0.jar,
    xmlbeans.2.5.0.jar,
    xmlentitymanager.jar,
    xml-apis-1.0.b2.jar

    Do i need to add/remove anything to sort out the above issue.

    Thanks,

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: APACHE POI 2007 word documents

    "Deployed all the jar files in my Eclipse Buildpath." That is only relevant to compiling the code. What matters is what is deployed to the web server where the application is actually executed.

    As for what you need to add/remove, I don't know. You will need to check the documentation of whatever stuff you're using. The exception seems to pass a hint that the xbeans jar might be of the wrong version, did you research into that?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Java applet to open word documents
    By james67 in forum Java Applets
    Replies: 0
    Last Post: 11-21-2013, 03:00 PM
  2. Java applet to open word documents
    By james67 in forum New To Java
    Replies: 0
    Last Post: 11-21-2013, 03:00 PM
  3. Replies: 0
    Last Post: 08-13-2012, 09:00 AM
  4. Object embedding with Word Document 2007
    By ramuksasi in forum Apache POI
    Replies: 8
    Last Post: 03-14-2012, 04:09 PM
  5. APACHE POI 2007 word documents
    By wildheart25c in forum Advanced Java
    Replies: 0
    Last Post: 06-20-2011, 05:49 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
  •