3

I've been trying to integrate docx4j with a custom JIRA plugin and I'm having a hell of a time. The first approach was to add:

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>3.3.2</version>
</dependency>

to the pom.xml file. The plugin built fine, but deployed (through the UPM) in a disabled state and gave a warning about missing functionality. I checked the logs and the base error seemed to be:

Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle <project_bundle> [233]: Unable to resolve 233.0: missing requirement [233.0] osgi.wiring.package; (osgi.wiring.package=com.google.appengine.api.images)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:400)

That led down a rabbit hole of adding exclusions to Import-Package in the instructions portion of the pom.xml to fix the unresolved constraints. I eventually got to the end of that and then also changed the dependency to:

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>3.3.2</version>
    <exclusions>
        <exclusion>
            <artifactId>*</artifactId>
            <groupId>*</groupId>
        </exclusion>
    </exclusions>
</dependency>

This led to the plugin successfully deploying, but being unable to use actually use docx4j in the code without it erroring out. And that's kind of where I am now.

My question is, does anyone have experience integrating docx4j with a JIRA plugin or know how to troubleshoot these problems?

I'm using docx4j version 3.3.2 and JIRA 7.1.7.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Ben
  • 960
  • 8
  • 17
  • Does this error occur if you just make the POM change and nothing else (ie. no code changes?) In your pom.xml, find the JIRA/Maven config section (under `com.atlassian.maven.plugins maven-jira-plugin ... `), and add a new configuration item: `false`. After that, delete the `target` directory, rebuild and re-load your plugin. Does it work? As an aside, it never hurts to place an explicit `compile` on your dep, even though that's the default. – Scott Dudley Feb 10 '17 at 18:37
  • I tried adding the `` tag, but it still resulted in a deployment error. The deployment error still occurs if the POM is changed and the code is not present. – Ben Feb 11 '17 at 16:38
  • It is odd that just changing the pom produces this impact, since the OSGi import error should not generally depend on what is packaged with it as libraries. Can you: 1- nuke target dir, remove dep from pom, build jar and save a copy. 2- add back the dep, repeat all previous steps, build another jar. After that, can you extract both jars and diff the contents? You should see a few new jars in META-INF/lib but not much else in terms of changes. – Scott Dudley Feb 11 '17 at 16:43

1 Answers1

1

At last, YES.

    <dependencies>
        <dependency>
            <groupId>com.googlecode.jaxb-namespaceprefixmapper-interfaces</groupId>
            <artifactId>JAXBNamespacePrefixMapper</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j</artifactId>
            <version>6.1.2</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.woodstox</groupId>
            <artifactId>woodstox-core</artifactId>
            <version>5.0.2</version>
        </dependency>


        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
            <!--that provided REALLY matters-->
        </dependency>


        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.3</version>
            <scope>provided</scope>
            <!--along with that-->
        </dependency>
    </dependencies>

and import-packages:

<!-- Add package import here -->
<Import-Package>
    org.springframework.osgi.*;version="0";resolution:=optional,
    org.eclipse.gemini.blueprint.*;resolution:="optional",
    org.docx4j*;resolution:="required",
    javax.ws.rs*;resolution:="required",
    javax.xml.bind*;resolution:="required",
    *;version="0";resolution:="optional"
</Import-Package>

And usage should be like that:

ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
try{
    //...different docx4j things
}finally{
    Thread.currentThread().setContextClassLoader(currentClassLoader);
}

Also (don't now know if it does matter, pretty sure it isn't), docx4j jar is also added to JIRA's /lib directory. Problem was in conflict between docx4j and JIRA's internal javax.xml - I've experimented with new pure JIRA plugin, containing only that functionality with docx4j - to manage only absolutely required dependencies

It's of course too late for the original answer, but I hope, that may help someone else.

user2501323
  • 227
  • 3
  • 12