docx4j integration in Jira

Hello.

I made a standalone application using docx4j and I'm able to create a docx file. Now I need to integrate it into a Jira 6.0 environment and I got the following exception.

2013-08-28 10:20:13,515 ThreadPoolAsyncTaskExecutor::Thread 14 ERROR      [extender.internal.activator.ContextLoaderListener] Application context refresh failed (NonValidatingOsgiBundleXmlApplicationContext(bundle=it.mycompany.myplugin, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mycompany-myplugin-component-document-builder' defined in URL [bundle://120.0:0/META-INF/spring/atlassian-plugins-components.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [docx.DocxDocumentExporter]: : Error creating bean with name 'docxDocumentExporter' defined in URL [bundle://120.0:0/META-INF/spring/myplugin-spring-context.xml]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'docxDocumentExporter' defined in URL [bundle://120.0:0/META-INF/spring/myplugin-spring-context.xml]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:591)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)

[...]

Caused by: java.lang.ClassCastException: org.apache.xalan.processor.TransformerFactoryImpl cannot be cast to javax.xml.transform.TransformerFactory
    at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
    at org.docx4j.XmlUtils.instantiateTransformerFactory(XmlUtils.java:209)
    at org.docx4j.XmlUtils.<clinit>(XmlUtils.java:120)
    ... 47 more

My code is

public class DocxDocumentExporter implements ApplicationContextAware {

    private ApplicationContext applicationContext;
    public static JAXBContext context = org.docx4j.jaxb.Context.jc;

[...]

and I solved this exception excluding in pom.xml file the xml-apis library from being loaded in the dependencies

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>2.8.1</version>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Now the plugin is correctly loaded but I have the following exception when I try to read the docx template to fill with my data.

org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml

I suppose it's a problem of a not correctly initialized JAXBContext but can anyone to suggest me which is the correct way to integrate docx4j in Jira ?

Thank you in advance

1 answer

1 accepted

This widget could not be displayed.

After four days of attempts I found the solution. In my pom.xml I added

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.3</version>
</dependency>

now the context is no more null and the plugin works also into Jira.

I't's just strange because I'm using Java 1.7.0_15 and in docx4j pom.xml these two dependencies are commented and they say to uncomment if used with Java 5

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

150 views 16 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you