Page 1 of 1

InvalidFormatException by using docx4j with eclipse

PostPosted: Wed Jul 27, 2011 5:36 am
by D3nnis
Good evening,
I want to use docx4j with some programes I've written a while ago as an outputting method.

As my first try, I wanted to simply read a docx-File but the few lines:
Code: Select all
package word;

import java.io.File;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;

public class ReadDocX {

   public static void main(String[] args) throws Docx4JException {
      String inputfilepath = "bsp/test.docx";
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
            .load(new File(inputfilepath));
   }
}

are causing me the following error-messages:
Code: Select all
0 [main] INFO org.docx4j.utils.Log4jConfigurator  - Since your log4j configuration (if any) was not found, docx4j has configured log4j automatically.
198 [main] INFO org.docx4j.jaxb.Context  - JAXB: RI not present.  Trying Java 6 implementation.
199 [main] INFO org.docx4j.jaxb.Context  - JAXB: Using Java 6 implementation.
199 [main] INFO org.docx4j.jaxb.Context  - loading Context jc
210 [main] ERROR org.docx4j.jaxb.Context  - Cannot initialize context
java.lang.NullPointerException
   at javax.xml.bind.ContextFinder.find(ContextFinder.java:270)
   at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
   at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
   at org.docx4j.jaxb.Context.<clinit>(Context.java:76)
   at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:643)
   at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
   at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:198)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:170)
   at word.ReadDocX.main(ReadDocX.java:13)
213 [main] ERROR org.docx4j.openpackaging.contenttype.ContentTypeManager  - java.lang.NullPointerException
Exception in thread "main" org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
   at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:676)
   at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
   at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:198)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:170)
   at word.ReadDocX.main(ReadDocX.java:13)
Caused by: java.lang.NullPointerException
   at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:643)
   ... 5 more


I'm using:
Eclipse - version: 3.5.2
Java - version "1.6.0_26" (x86)
Win7 Professional x64

As u can see on the linked image, I've put the docx4j-jar's into a "UserLibrary" and linked it with my project.
Image

Am I missing some important steps for using docx4j? I couldn't find some instructions for proper using in eclipse on the documentation.
And please don't tease me if the solution is just too easy.. ^^

Looking forward for any helpful answer
Dennis

Re: InvalidFormatException by using docx4j with eclipse

PostPosted: Wed Jul 27, 2011 9:48 am
by jason
That's a weird error.

Taken at face value, JAXB can't find a context with which to read [Content_Types].xml from the docx

Every docx file has [Content_Types].xml, so of course it should be able to read it.

Unless there is something unusual about the docx, or about your docx4j jar file.

What program was it created with? Can Word 2007 or 2010 open it? Can you attach it to a post?

The only other thing that stands out is that you say you are running x86 Java on x64 Windows. I've never done that, so I don't know whether that could cause issues.

Re: InvalidFormatException by using docx4j with eclipse

PostPosted: Wed Jul 27, 2011 11:45 am
by D3nnis
The file I'm using has been created with Word 2010, therefore it can open it normally. I don't have a 2007 version here so that I can't test it, but the only content of this file is one paragraph "Hello World!". I've attached the file on this post...

The jar-files have been extracted out of this archive: http://dev.plutext.org/docx4j/docx4j-2.7.0.tar.gz


I'm running the x86 Java on my System because the x64 version caused some errors with some programs I used in the past.. don't know if it was jDownloader, Minecraft or what ever...
I'll try installing 64bit Java this night or tomorrow....

Re: InvalidFormatException by using docx4j with eclipse

PostPosted: Wed Jul 27, 2011 8:31 pm
by tinne
You can run either 32- or 64-bit Java on Windows 64, either way, you are getting a perfectly normal view on the system (32 bit is running on the 32 bit subsystem called SYSWOW). You cannot, however, link native libraries of the other kind (64-bit dlls from a 32-bit java or vice versa) in one process, and 32-bit programs see the file system somehow mangled (e.g. windows\syswow\ for windows\system32\) else there should be no problems. You however want to run the 64 bit java when you encounter memory problems, as 64 bit java can allocate much more heap space.

Re: InvalidFormatException by using docx4j with eclipse

PostPosted: Thu Jul 28, 2011 1:34 am
by jason
Hi Dennis

I created a project in eclipse from scratch, put the contents of docx4j-2.7.0.tar.gz on my build path, and successfully opened your docx.

Code: Select all
0 [main] INFO org.docx4j.utils.Log4jConfigurator  - Since your log4j configuration (if any) was not found, docx4j has configured log4j automatically.
329 [main] INFO org.docx4j.jaxb.Context  - JAXB: RI not present.  Trying Java 6 implementation.
329 [main] INFO org.docx4j.jaxb.Context  - JAXB: Using Java 6 implementation.
329 [main] INFO org.docx4j.jaxb.Context  - loading Context jc
5164 [main] INFO org.docx4j.jaxb.Context  - loaded com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl .. loading others ..
5330 [main] INFO org.docx4j.jaxb.Context  - .. others loaded ..
5381 [main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager  - Detected WordProcessingML package
5390 [main] INFO org.docx4j.openpackaging.parts.Part  - /_rels/.rels
:


For what its worth, this was on Win 7 x64 with Eclipse 3.5.2 and Java 1.6.0_19 x64. (Though I've never had a similar issue on Linux (x64) or other version of eclipse)

In case JAXB is swallowing an OutOfMemory exception, you could try adding -Xmx512m to your run configuration.

Re: InvalidFormatException by using docx4j with eclipse

PostPosted: Thu Jan 12, 2012 12:02 pm
by alex
I've used Java 6 instead of Java 5 and that solved the issue for me.