Page 1 of 1

Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Wed Aug 05, 2009 2:33 pm
by noseya
Hi all !

I'm new with docx4j and i cant get started due to this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/bind/marshaller/NamespacePrefixMapper
at org.docx4j.openpackaging.io.LoadFromZipNG.getRelationshipsPartFromZip(LoadFromZipNG.java:264)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:214)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:179)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:161)
at Docx4jTest.main(Docx4jTest.java:12)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.marshaller.NamespacePrefixMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 5 more

I searched for this class and i found it in another package com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper.

I dont know what to do. Im using Java 6. Any help is appreciated. Thanks!

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Wed Aug 05, 2009 3:25 pm
by jason
I'm not sure what exactly your Docx4jTest.java does, but...

With the latest code (v2.2 or current svn), you should be able to use just Java 6's included JAXB implementation. This uses com.sun.xml.*internal* NamespacePrefixMapper stuff.

Alternatively, you can put the JAXB reference implementation in your endorsed dir. That will use com/sun/xml/bind/marshaller/NamespacePrefixMapper (ie not the Sun internal one)

In order for users to have the choice of these two different JAXB implementations, if you want to build docx4j yourself, you'll need both JAXB implementations on your classpath.

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Wed Aug 05, 2009 6:45 pm
by noseya
Thanks for your reply Jason.

I'm using v2.2. New Eclipse Project with clean Java 6 and all libs that come with docx4j-2.2.0.tar.gz. My code fails at first line:

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File("/sample.docx"));

I checked a bit more and i finded here http://dev.plutext.org/svn/docx4j/trunk ... lPart.java that com.sun.xml.bind.marshaller.NamespacePrefixMapper is used as type parameter at line 132, i think thats the problem.

Thanks for your help!

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Wed Aug 05, 2009 11:26 pm
by jason
Thanks for this. I think you're right. I'll try to fix this tomorrow.

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Thu Aug 06, 2009 12:07 am
by jason
Could you please try r 866; this should fix the problem you identified. There may be other similar cases; I haven't looked yet. Thanks.

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Sun Aug 09, 2009 11:50 pm
by eford
I was previously having some success adding images using the docx4j-nightly-20090528 version. However, after upgrading to docx4j 2.2.0 I started encountering problems again with com.sun.xml.bind.marshaller.NamespacePrefixMapper. I grabbed the source from svn (r 869) and Eclipse is reporting errors involving this reference in org.docx4j.jaxb.NamespacePrefixMapper and org.docx4j.jaxb.NamespacePrefixMapperRelationshipPart - both of which extend the indicated class. I changed the org.docx4j.jaxb.NamespacePrefixMapper class to extend com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper and then changed org.docx4j.jaxb.NamespacePrefixMapperRelationshipPart to extend org.docx4j.jaxb.NamespacePrefixMapper. I'm not sure if this is what you had in mind to do but after these changes, the AddImage.java sample seems to correctly embed an image into a docx file again, however, I am getting a new exception due to org.apache.batik.bridge.UserAgent not being in the classpath.

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Mon Aug 10, 2009 10:01 pm
by jason
eford wrote:I was previously having some success adding images using the docx4j-nightly-20090528 version. However, after upgrading to docx4j 2.2.0 I started encountering problems again with com.sun.xml.bind.marshaller.NamespacePrefixMapper. I grabbed the source from svn (r 869) and Eclipse is reporting errors involving this reference in org.docx4j.jaxb.NamespacePrefixMapper and org.docx4j.jaxb.NamespacePrefixMapperRelationshipPart - both of which extend the indicated class.


If you are compiling from source (or using docx4j source in Eclipse - although in this case you might be able to ignore the error), you will need both the JAXB reference implementation, and Java 6 implementation.

If you are using a docx4j distribution based on r869, you should need just one of the 2 implementations. I will create a docx4j distribution based on r869, probably tomorrow.

eford wrote:the AddImage.java sample seems to correctly embed an image into a docx file again, however, I am getting a new exception due to org.apache.batik.bridge.UserAgent not being in the classpath.


Is this a fatal error? iirc, there may be a warning message related to batik, but it has not caused problems for me in the past. Is it possible you have some version of fop or xml-graphics say, different from the docx4j versions?

Re: Problem with com.sun.xml.bind.marshaller.NamespacePrefixMapp

PostPosted: Mon Aug 10, 2009 10:19 pm
by eford
If you are compiling from source (or using docx4j source in Eclipse - although in this case you might be able to ignore the error), you will need both the JAXB reference implementation, and Java 6 implementation.

If you are using a docx4j distribution based on r869, you should need just one of the 2 implementations. I will create a docx4j distribution based on r869, probably tomorrow.


In this case I was using the r869 source files from svn and running the AddImage.java sample within Eclipse.

Is this a fatal error? iirc, there may be a warning message related to batik, but it has not caused problems for me in the past. Is it possible you have some version of fop or xml-graphics say, different from the docx4j versions?


I was using the fop and xml-graphics jars from the docx4j 2.2 release. It was not a fatal error. I only noticed it in the Eclipse console later when researching another problem. My bigger problem is actually the one I reported in another topic dealing with inserting images when running on the server.