Get error when using metadata jar in fat jar

I created fat jar with groupdocs-metadata-24.12.jar to add keywords to docx file. Got the error message :

at com.groupdocs.metadata.core.MetadataAssemblyConstants.getInstance(Unknown Source)
at com.groupdocs.metadata.licensing.License.setLicense(Unknown Source)

Caused by: java.lang.NullPointerException
at com.groupdocs.metadata.core.MetadataAssemblyConstants.bph(Unknown Source)
at com.groupdocs.metadata.core.MetadataAssemblyConstants.(Unknown Source)
at com.groupdocs.metadata.core.MetadataAssemblyConstants.(Unknown Source)
at com.groupdocs.metadata.core.MetadataAssemblyConstants$a.(Unknown Source)

How to fix the problem? Thanks.

1 Like

@dngl250326

To better understand the issue, could you share more details? Specifically, it would help if you could provide the part of your code where you set the license and modify the metadata, details about your project setup (how you’re packaging and running the Fat JAR), the Java version you’re using, and if possible, a sample DOCX file that reproduces the issue. This will help us investigate and provide a solution.

I use the following code to add keyword metadata to a docx file. It works in my eclipse. While I create a jar file and deploy it onto Adobe Livecycle server. I got that error. It might be dependency conflicts. FYI, I also tried Aspose.Total. It doesn’t have such problem. As Metadata library is more specific for my purposes, I prefer to use it if the problem could be solved. Regards.

image.png (11.7 KB)

@dngl250326
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): METADATAJAVA-677

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello @dngl250326

As a quick solution, we suggest not packaging the library file into the fat JAR, but instead placing it next to the fat JAR.

Please clarify your task — what is the specific need to have only a single JAR file?

If possible, please provide a minimal project for testing.

Hello Yuriy,

I created a component for Adobe Livecycle(running on JBoss). It need to be a jar with my classes and all its required libraries. It runs ok on my machine. While I deployed on to the Adobe livecycle server, I got the error messages. Is there anyway to include all dependencies and shade names in order to make your libraries loading class from its own?

Regards,

Dong

~WRD0000.jpg (357 Bytes)

Hi @dngl250326

If you’re building a custom component for Adobe LiveCycle (running on JBoss), and it works fine locally but fails with errors when deployed to the LiveCycle server, the issue is likely due to classpath conflicts. LiveCycle runs inside a JBoss container, which already includes many libraries (e.g., commons-logging, slf4j , etc.).
If your component uses the same libraries, conflicts can occur, leading to ClassCastException, NoClassDefFoundError, or NullPointerException.

Solution: Create a “shaded JAR” with isolated dependencies. To ensure your component uses its own dependencies , and not those provided by the server, you need to:

  1. Use shadow (for Gradle) or maven-shade-plugin (for Maven)

Example with Gradle :

plugins {
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}

shadowJar {
    relocate 'org.apache.commons', 'yourpackage.shaded.org.apache.commons'
    relocate 'com.google.gson', 'yourpackage.shaded.com.google.gson'
    // Relocate any other dependencies as needed
}

Example with Maven :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.4.1</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals><goal>shade</goal></goals>
      <configuration>
        <relocations>
          <relocation>
            <pattern>org.apache.commons</pattern>
            <shadedPattern>yourpackage.shaded.org.apache.commons</shadedPattern>
          </relocation>
        </relocations>
      </configuration>
    </execution>
  </executions>
</plugin>

This approach repackages your dependencies under a different namespace to avoid conflicts with the server’s global libraries.

Hope it will help!

Hi Yuriy,

Thanks for your sugggestion. I tried to use shade plugin in Maven to rename classes. But it still doesn’t work for me. The error message : “Caused by: java.lang.NoClassDefFoundError: Could not initialize class shaded.org.apache.poi.xwpf.usermodel.XWPFDocument “. I checked the new jar file which contains the class. I have no idea.

Regards,

Dong

@dngl250326

Here are few ideas to solve the issue

  1. Since you’re getting this error:
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class shaded.org.apache.poi.xwpf.usermodel.XWPFDocument it means the class was found, but failed during static initialization. So the issue is not a missing class, but rather something deeper — here are the most likely causes and how to fix them: Possible Causes & Fixes
  2. Missing transitive dependencies (even after shading) Even if you shaded poi itself, it depends on many other libraries like:
  • poi-ooxml
  • poi-ooxml-schemas
  • xmlbeans
  • commons-compress
  • ooxml-schemas If those aren’t included and relocated in your shaded JAR, the class will fail to initialize. Fix: Make sure to include and relocate all transitive dependencies. Use this command to inspect them:
mvn dependency:tree

Then add <relocation> entries for each in your maven-shade-plugin config. —
2. Static initialization failure Sometimes a class fails during static block or static field initialization due to missing classes or bad environment (e.g., missing XML parsers, classloader issues, etc.). Fix: Try running your shaded JAR locally, outside the server, to see the full stack trace and determine what part of the class is causing the failure. —

new

  1. Classloader conflicts with JBoss/Adobe LiveCycle Even if you shaded everything, LiveCycle (JBoss) might still load conflicting classes from its own modules (like xmlbeans , poi , etc.). Fix: Add a jboss-deployment-structure.xml file to exclude those server-provided modules and isolate your deployment:
<jboss-deployment-structure>
  <deployment>
    <isolated>true</isolated>
    <exclusions>
      <module name="org.apache.poi" />
      <module name="org.apache.xmlbeans" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Put this file into META-INF/ of your JAR or WEB-INF/ of your WAR. What to do next:

  1. Unpack your shaded JAR and verify that it contains:
    * shaded/org/apache/poi/xwpf/usermodel/XWPFDocument.class
    * All transitive classes like XmlOptions , OPCPackage , etc.
  2. Run a test app using just the shaded JAR (outside LiveCycle) to ensure it works standalone.
  3. If it works locally, then the issue is definitely a classloader conflict on the server side.