Page 1 of 1

Unable to load docx file

PostPosted: Tue Sep 04, 2018 6:50 pm
by adams
Hi Jason,

I updated my docx4j project from 3.3.5 to 6.0.1 and I have a wierd problem.

Code: Select all
Docx4J.load(new File(filePath));

The code above throws this exception:
Code: Select all
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't get [Content_Types].xml from ZipFile
   at org.docx4j.openpackaging.io3.Load3.get(Load3.java:148)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:523)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:379)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:345)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:310)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:184)
   at org.docx4j.Docx4J.load(Docx4J.java:272)
   at neti.component.processor.DocxProcessor.createWordMLPackage(DocxProcessor.java:229)
   ... 4 more
Caused by: org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
   at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:771)
   at org.docx4j.openpackaging.io3.Load3.get(Load3.java:146)
   ... 11 more
Caused by: java.lang.NullPointerException
   at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:737)
   ... 12 more


In debug mode I found the source maybe. It says
Context.jcContentTypes = Class not loaded : org.docx4j.jaxb.Context

Because of that unloaded class an inner exception generated with this message:
Method threw 'java.lang.RuntimeException' exception. Cannot evaluate org.docx4j.openpackaging.contenttype.ContentTypeManager.toString()

This exception coming from ContentTypeManager.java at line 737.

I hope you can help.

Best regards:
Adam

Re: Unable to load docx file

PostPosted: Tue Sep 04, 2018 9:24 pm
by adams
Okay, during the version update I changed my project from maven to gradle.
So I changed it back and now it's working with 6.0.1.

Re: Unable to load docx file

PostPosted: Tue Sep 04, 2018 9:35 pm
by jason
v6.0.1 uses commons-compress to unzip;; maybe that was missing from your classpath?

Re: Unable to load docx file

PostPosted: Tue Sep 04, 2018 9:49 pm
by adams
It is in my classpath. I don't know why this is not working with gradle.
I have the same dependencies and java code in gradle and maven.
And with maven it's working, with gradle still Class not loaded : org.docx4j.jaxb.Context error.

Re: Unable to load docx file

PostPosted: Wed Sep 05, 2018 8:10 pm
by jason
Ahhh, Java 9 :-)

Looks like we figured it out, at https://stackoverflow.com/questions/521 ... 7#52179187