docx4j integration in Jira

Francesco R
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2013

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

0 votes
Answer accepted
Francesco R
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2013

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