Search code examples
ms-wordjaxbdocx4j

docx4j Couldn't get [Content_Types].xml from ZipFile


I have been googling and trying various things such as placing a jaxb.properties file into my web2 folder to specify eclipselink but not having any luck at all.

I can run from eclipse simple code

String inputfilepath = "mywordfile.docx";

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
MainDocumentPart main = wordMLPackage.getMainDocumentPart();

But when it runs under jboss (same jdk, old version of jboss) I get

org.docx4j.openpackaging.exceptions.Docx4JException:
Couldn't get [Content_Types].xml from ZipFile

and I cant figure out an easy way to fix it. Most googling suggests changing the implementation of jaxb - but I am not marshalling my own classes so it doesnt make sense (nor have my attempts worked).

Any ideas?


Solution

  • To use EclipseLink/MOXy JAXB (as opposed to the Sun/Oracle version in the JDK or the reference implementation), you need:

    1. the relevant EclipseLink jars
    2. docx4j-MOXy-JAXBContext-3.0.0.jar (which just contains the jaxb.properties files)

    The jaxb.properties files just say:

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    If you are using maven, you'll just need to add:

    <dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-MOXy-JAXBContext</artifactId>
    <version>3.0.0</version>
    </dependency>
    
    <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
    <version>2.5.1</version>
    </dependency>
    

    When you start docx4j, the log output will tell you which JAXB it is using.