Page 1 of 1

java.lang.NoClassDefFoundError org/docx4j/XmlUtils

PostPosted: Thu Jul 14, 2016 1:26 am
by McPeter
I have a maven project which builds a jar using the following pom.xml

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.rechtspraak.services</groupId>
  <artifactId>DocxUtils</artifactId>
  <version>1.0.1628.1</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
    <mainClass>nl.rechtspraak.services.docxutils.DocxUtils</mainClass>
  </properties>
  <name>DocxUtils</name>
  <dependencies>
          <dependency>
      <groupId>org.docx4j</groupId>
      <artifactId>docx4j</artifactId>
      <version>3.3.0</version>
    </dependency>

   
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.13</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
     
<!--      <plugin><groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.0.1</version>
      <configuration>
          <archive>
              <manifest>
                  <addClasspath>true</addClasspath>
                  <classpathPrefix>lib</classpathPrefix>
               
              </manifest>
              <manifestEntries>
                  <Class-Path>lib/</Class-Path>
              </manifestEntries>
          </archive>
  </configuration>
      </plugin>-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
<!--                <filters>
                    <filter>
                        <artifact>docx4j:docx4j</artifact>
                        <includes>
                            <include>**</include>
                        </includes>
                    </filter>
                </filters>-->
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>${mainClass}</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>log4j.properties</include>
        </includes>
        <targetPath>nl/rechtspraak/services/docxutils</targetPath>
      </resource>
    </resources>
  </build>
</project>


The project builds find and the unit tests are successful. When using the compiled jar as a Spring Bean in an Oracle BPEL composite i get the following Exception;


Code: Select all
[2016-07-13T15:19:55.330+02:00] [esb_soa_server1] [ERROR] [OWS-04086] [oracle.webservices.service] [tid: [ACTIVE].ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: <anonymous>] [ecid: 370c1c2d426a9f58:14d40f5b:155e27aa52a:-8000-000000000000126f,0:2] [APP: soa-infra] [composite_instance_id: 4710159] [composite_name: docxdemo] [component_name: docxprotect_client_ep] javax.xml.rpc.soap.SOAPFaultException: oracle.fabric.common.FabricInvocationException: weblogic.sca.api.ScaException: java.lang.NoClassDefFoundError: org/docx4j/XmlUtils[[
        at oracle.integration.platform.blocks.soap.WebServiceEntryBindingComponent.generateSoapFaultException(WebServiceEntryBindingComponent.java:1280)
        at oracle.integration.platform.blocks.soap.WebServiceEntryBindingComponent.processIncomingMessage(WebServiceEntryBindingComponent.java:1053)
        at oracle.integration.platform.blocks.soap.FabricProvider.processMessage(FabricProvider.java:113)
        at oracle.j2ee.ws.server.provider.ProviderProcessor.doEndpointProcessing(ProviderProcessor.java:1187)
        at oracle.j2ee.ws.server.WebServiceProcessor.invokeEndpointImplementation(WebServiceProcessor.java:1123)
        at oracle.j2ee.ws.server.provider.ProviderProcessor.doRequestProcessing(ProviderProcessor.java:581)
        at oracle.j2ee.ws.server.WebServiceProcessor.processRequest(WebServiceProcessor.java:235)
        at oracle.j2ee.ws.server.WebServiceProcessor.doService(WebServiceProcessor.java:196)
        at oracle.j2ee.ws.server.WebServiceServlet.doPost(WebServiceServlet.java:487)


Inspecting the jar, the class is indeed not available in the build jar. The downloaded version of docx4j-3.3.0.jar from docx4j.org does contain this class in org.docx4j.
How to modify to also get these classes in the target jar?

Re: java.lang.NoClassDefFoundError org/docx4j/XmlUtils

PostPosted: Thu Jul 14, 2016 7:05 pm
by McPeter
Seems to be that some classes in the existing classpath Weblogic / JRockit 1.6 are of higher versions than supported by docx4j.
After adding the following dependency and setting the classpath in the manifest the java.lang.NoClassDefFoundError: org/docx4j/XmlUtils is fixed.

Code: Select all
<dependency>
      <groupId>javax.xml.parsers</groupId>
      <artifactId>jaxp-api</artifactId>
      <version>1.4.1</version>
</dependency>


Now the following exeption has to be resolved

Code: Select all
java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
    at javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(DocumentBuilderFactory.java:590)
    at org.docx4j.XmlUtils.<clinit>(XmlUtils.java:248)

Re: java.lang.NoClassDefFoundError org/docx4j/XmlUtils

PostPosted: Fri Jul 22, 2016 7:12 pm
by jason
McPeter wrote:Inspecting the jar, the class is indeed not available in the build jar.


I added the shade plugin to docx4j's pom, at https://github.com/plutext/docx4j/blob/ ... m.xml#L241

It resulted in a shaded jar which looks complete.

So I'm not sure what is going wrong in your case. You might have more luck finding an answer via maven's support channels.

McPeter wrote:java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
at javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(DocumentBuilderFactory.java:590)
at org.docx4j.XmlUtils.<clinit>(XmlUtils.java:248)


See the comment at new commit https://github.com/plutext/docx4j/commi ... bc7f7e9ebb (which works around this issue):

// org.apache.xerces.jaxp.DocumentBuilderFactoryImpl v2.6.2
// (which docx4j doesn't use by default)
// throws java.lang.UnsupportedOperationException
// Apparently can be fixed by upgrading to 2.9.1


So if you are using that, upgrade it.

If necessary, you can configure your DocumentBuilder using docx4j property "javax.xml.parsers.DocumentBuilderFactory"

With INFO level logging turned on for XmlUtils, docx4j 3.3.1 beta will tell you what class is actually being used.

The above commit isn't in 3.3.1 beta, but will be in 3.3.1 when released.