0

I had a maven project with old docx4j dependencies, and I wanted to update to java 9. During the update I changed my project from maven to gradle.

So now I have a gradle project in IntelliJ with this dependencies:

dependencies {
    implementation('commons-io:commons-io:2.6')
    implementation('javax.xml.bind:jaxb-api:2.4.0-b180725.047')
    implementation('org.docx4j:docx4j:6.0.1')
    implementation('org.docx4j:docx4j-ImportXHTML:6.0.1')
    implementation('org.docx4j:docx4j-export-fo:6.0.1')
    testImplementation('junit:junit:4.12')
}

The build is working, but if I want to open a .docx file, with Docx4J.load(...) or WordprocessingMLPackage.load(...) it throws a RuntimeException. In debug mode I can see this message: Class not loaded : org.docx4j.jaxb.Context

This Context.java file has a static code block like this:

static {
    ...
}

I think it's gradle specific error, because I created a new maven project with the same code and dependencies as the gradle project, and it works.

Is there any solution for this, or should I use maven in the future too?

Adam
  • 48
  • 7

1 Answers1

0

There is a Gradle-specific answer at https://stackoverflow.com/a/51235096/1031689

Or to "add module" instead, see for example:

Or mac java 9 gradle ClassNotFoundException: javax.xml.bind.JAXBElement when building

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Thank you for your answer. The first link was right for me. I added 2 more dependencies (jaxb-core and jaxb-impl) and now its working. I dont know why these dependencies were not necessary for maven. – Adam Sep 05 '18 at 08:43
  • Great. If you'd like to contribute your working Gradle file, I'll add it to docx4j :-) – JasonPlutext Sep 05 '18 at 09:12
  • Sure. I prefer glassfish over sun, so I have the above dependencies plus these: org.glassfish.jaxb:jaxb-core:2.3.0.1 org.glassfish.jaxb:jaxb-runtime:2.3.0.1 – Adam Sep 07 '18 at 09:28