Page 1 of 1

JBOSS issues

PostPosted: Mon Jul 13, 2009 7:58 pm
by hugopais
Hi everyone,

I'm currently starting to use docx4j and i'm having trouble when loading any docx document. I'm using JBOSS and the error it gives is the following:

2009-07-13 18:56:21,577 INFO [org.docx4j.openpackaging.parts.Part] Constructing /_rels/.rels
2009-07-13 18:56:23,138 ERROR [STDERR] javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "objectFactory". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.docx4j.wml.ObjectFactory
this problem is related to the following location:
at org.docx4j.dml.ObjectFactory

- with linked exception:
[com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "objectFactory". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.docx4j.wml.ObjectFactory
this problem is related to the following location:
at org.docx4j.dml.ObjectFactory
]
2009-07-13 18:56:23,138 ERROR [STDERR] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:162)


Any ideas on what is happening?

Thanks in advance
Hugo Pais

Re: Error loading docx

PostPosted: Tue Jul 14, 2009 4:23 am
by jason
Which version of JAXB are you using?

Problem is likely to be to do with whether JBOSS is using its own copies of JAXB, rather than yours.

Maybe http://bimalesh.blogspot.com/2007/05/jb ... dk-16.html helps?

Re: Error loading docx

PostPosted: Thu Jul 16, 2009 12:55 pm
by hugopais
Thanks for the help.

It was in fact JBOSS loading a wrong version of JAXB (2.0.3).

After solving this one i end up getting a new one a little more tricky. Apparently JBOSS uses a different classloader to load JAXBContext and the only way to solve it was to explicity indicate which classloader it should use:

Context.jc = JAXBContext.newInstance("org.docx4j.wml:org.docx4j.dml",this.getClass().getClassLoader());
Context.jcThemePart = JAXBContext.newInstance("org.docx4j.dml",this.getClass().getClassLoader());
Context.jcDocPropsCore = JAXBContext.newInstance("org.docx4j.docProps.core:org.docx4j.docProps.core.dc.elements:org.docx4j.docProps.core.dc.terms",this.getClass().getClassLoader());
Context.jcDocPropsCustom = JAXBContext.newInstance("org.docx4j.docProps.custom",this.getClass().getClassLoader());
Context.jcDocPropsExtended = JAXBContext.newInstance("org.docx4j.docProps.extended",this.getClass().getClassLoader());
Context.jcXmlPackage = JAXBContext.newInstance("org.docx4j.xmlPackage",this.getClass().getClassLoader());
Context.jcRelationships = JAXBContext.newInstance("org.docx4j.relationships",this.getClass().getClassLoader());

Regards
Hugo Pais

Re: Error loading docx

PostPosted: Fri Jul 17, 2009 8:24 am
by jason
Thanks for this; will be useful for anyone else using docx4j with JBOSS.

I guess Context.java should be changed so it works with JBOSS out of the box. I'll test to see whether this.getClass().getClassLoader() causes any issues with Tomcat first.

Re: Error loading docx

PostPosted: Tue Jul 21, 2009 10:21 pm
by Leigh
Hi Hugo,

Can you show how you implemented that change in the code? In the base version those statements are inside a static block, so I was wondering how you were able to sneak in the "this" reference.

Thank You,
-Leigh

Re: Error loading docx

PostPosted: Mon Jul 27, 2009 1:37 am
by Leigh
Hi,

I am still looking into how to use this.getClass().getClassLoader() with the JAXBContext. So if anyone has any ideas, feel free to chime in.

Cheers

Re: Error loading docx

PostPosted: Wed Sep 16, 2009 7:52 am
by jason
jason wrote:Thanks for this; will be useful for anyone else using docx4j with JBOSS.

I guess Context.java should be changed so it works with JBOSS out of the box.


See revision 894. I don't think all versions of JBOSS are affected, but this fix doesn't distinguish between environments at all (JBOSS or otherwise).

Re: JBOSS issues

PostPosted: Thu Sep 17, 2009 2:49 pm
by eford
See revision 894. I don't think all versions of JBOSS are affected, but this fix doesn't distinguish between environments at all (JBOSS or otherwise).


It appears to be version specific - I'm working with JBoss 4.2.1.GA and have not encountered either of these problems.