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.
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.