Page 1 of 1

Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Wed Dec 19, 2012 1:20 am
by arimmer
Everything works fine with docx4j 2.6.0 jar file, but simply replacing that jar with the 2.8.1 jar file (from 30th Sept) and running some code which produces a report in Word 2007 format (writing only, no reading of docx files) gives the following error message:
Code: Select all
18-Dec-2012 14:08:23,270 DEBUG [] - StasysLogger.debug() - Successfully loaded and initialised generator for Management
Exception in thread "pool-1-thread-1" java.lang.ExceptionInInitializerError
   at org.docx4j.openpackaging.parts.JaxbXmlPart.<init>(JaxbXmlPart.java:79)
   at org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.<init>(JaxbXmlPartXPathAware.java:64)
   at org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart.<init>(DocumentPart.java:157)
   at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.<init>(MainDocumentPart.java:76)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:432)
   at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:421)
   at ...... (local file references)
   at java.lang.Thread.run(Thread.java:619)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
   at javax.xml.bind.ContextFinder.find(ContextFinder.java:270)
   at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
   at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
   at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:47)
   at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
   ... 19 more


Running on Java 1.6.0_18 (tho' same problem occurs with 1.6.0_38).
Simply replaced the jar file in lib directories and Tomcat(5.5.28) endorsed directory. No other changes made.

We've run out of ideas as to where we should look to solve this problem - any pointers would be much appreciated.

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Wed Dec 19, 2012 1:25 am
by arimmer
Solved it myself - docx4j should not be in the Tomcat endorsed directory. Took it out and everything runs fine.

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Thu Jan 03, 2013 12:38 am
by arimmer
As previously posted removing the jar file from the endorsed directory works for my application when running in Tomcat (Client/Server mode).

However, my application can also be built/run as a standalone application, and I can not get this to run successfully with v2.8.1.

The standalone application has an 'endorsed' directory - putting the 2.6.0 jar file in this directory allows it to run successfully.

Upgrading to the 2.8.1 jar file gives a similar stack trace to that given above if the jar file is in the 'endorsed' directory ('Caused by' part is identical). However, if I remove the jar file from the 'endorsed' directory, so now it is only in the applications 'lib' directory, I get the following stack trace:

Code: Select all
02-Jan-2013 13:23:11,785 ERROR [] - StasysLogger.error() - General Exception in execute
java.lang.NoClassDefFoundError: org/docx4j/openpackaging/exceptions/Docx4JException
   at [local file line numbers]
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.Component.processMouseEvent(Component.java:6263)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6028)
   at java.awt.Container.processEvent(Container.java:2041)
   at java.awt.Component.dispatchEventImpl(Component.java:4630)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
   at java.awt.Container.dispatchEventImpl(Container.java:2085)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: org.docx4j.openpackaging.exceptions.Docx4JException
   at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
   ... 41 more
[local class details].ConnectorException: org/docx4j/openpackaging/exceptions/Docx4JException
   [local class details]
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
   at java.awt.Component.processMouseEvent(Component.java:6263)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6028)
   at java.awt.Container.processEvent(Container.java:2041)
   at java.awt.Component.dispatchEventImpl(Component.java:4630)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
   at java.awt.Container.dispatchEventImpl(Container.java:2085)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Looks to me like it is trying to find the DocX4JException so it can create one. As I can definitely see the DocX4JException within the 2.8.1 jar in the applications 'lib' directory I don't understand how the application can run, as it is in jar files in the 'lib' directory too, but not find this class.

Any ideas as to what might be the cause of this? Is it possible that a dependency that was introduced between 2.6.0 and 2.8.1 is missing?

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Mon Jan 07, 2013 3:53 pm
by jason
As a general comment, you shouldn't be putting docx4j in the endorsed dir.

arimmer wrote:Is it possible that a dependency that was introduced between 2.6.0 and 2.8.1 is missing?


That is possible.

You could compare the dependencies in http://www.docx4java.org/docx4j/docx4j-2.6.0/ to those in http://www.docx4java.org/docx4j/docx4j-2.8.1/

The absence of jaxb-*.jar and in particular jaxb-xmldsig-core-1.0.0.jar is likely causing your javax.xml.bind.JAXBContext.newInstance problem.

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Wed Jan 09, 2013 3:41 am
by arimmer
I've tried adding jaxb-xmldsig-core-1.0.0.jar to both the 'lib' and 'endorsed' directories of my standalone application, and also adding all the jar files that are dependencies (even the ones for things we're not doing) to both these directories, but the error messages are unchanged!!

Really not sure what to try next, so any suggestions would be very welcome.


[On a side note, I found the documentation for the dependencies in 2.8.1 did not seem to include all the jar files, so I put together my best guess of which files are used for/required by what functionality in a spreadsheet, which I have attached in case it is of any use to anyone else]

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Wed Jan 09, 2013 7:20 am
by jason
Sounds like you might need to go back to basics: a clean install of tomcat, and a simple webapp (all of docx4j's jars in WEB-INF/lib, and some simple servlet that uses docx4j to do something).

Once you have satisfied yourself that this works, you can add other stuff.

Again, the only things which should go in your endorsed dir are the JAXB reference implementation, or Xerces or Xalan, if you want to use these instead of what is supplied as part of Java 6 or 7. docx4j and its dependencies (with the exception of Xalan), don't go there. See further http://tomcat.apache.org/tomcat-7.0-doc ... howto.html

Re: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Thu Jan 10, 2013 3:17 am
by arimmer
I don't have any problem when running within Tomcat.

It is when running as a standalone application (same code as run in Tomcat when it gets as far as the DocX4J stuff) that I get the problem.

The application has the following directory structure:
<appRoot>
|-------- conf
|-------- endorsed
|-------- images
|-------- lib

Where 'endorsed' contains the jar files found in the Tomcat endorsed directory for the Client/Server version. And the 'lib' contains all jar files required for the application, both our own and various 3rd party jars including DocX4J.

When we were using the 2.6.0 version of DocX4J we found that we needed to put it into the 'endorsed' directory for both Standalone and Client/Server versions and everything worked fine.

Now we need to upgrade to the 2.8.1 version.
In Tomcat we found we needed to NOT put it into the endorsed directory - after I removed it everything works fine.

But in the standalone version, if it is not in the 'endorsed' directory of the standalone application, we get the 'class not found' error as in my post of January 2nd.
If we place the DocX4J jar file in the applications 'endorsed' directory (with or without the jaxb-xmldsig-core-1.0.0.jar file) we get the exact same 'NullPointerException' as originally posted.

So I guess the real question here is why would the standalone application be unable to find the DocX4J classes if the file is not in the 'endorsed' directory of the standalone application?

I did a little testing, and trying to access classes in the jaxb-xmldsig-core-1.0.0.jar causes the same problem, class not found, if not in standalone application 'endorsed' directory, but work fine when the jar file is placed in the application 'endorsed' directory.

Unfortunately we need to get both versions working as our customers are free to choose which version they want to run, and we know some choose one and some the other.

SOLVED: Odd problem replacing 2.6.0 jar with 2.8.1 jar

PostPosted: Thu Jan 24, 2013 10:52 pm
by arimmer
Solved my problem finally - after investigating classloaders, classpath etc.

Turns out when you run an application from a jar file using the -jar <jarfilename> option, you need to set all the correct classpath details within the manifest of that jar file.

Something I don't think I'd ever explicitly been told, or I was told so long ago I'd forgotten.

Added the docx4j jar to the classpath in the manifest and everything is fine.