0

I am getting the following error on a linux server machine. On my local machine it works just fine.

Exception created : java.lang.NoClassDefFoundError: org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage (initialization failure) at java.lang.J9VMInternals.initialize(J9VMInternals.java:140) at com.common.cmd.htmltodoc.newImage(htmltodoc.java:3932)

  public static P newImage( WordprocessingMLPackage wordMLPackage, byte[] bytes, 
            String filenameHint, String altText, int id1, int id2) throws Exception {

        BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
        Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false);

        ObjectFactory factory = new ObjectFactory();

        P  p = factory.createP();
        R  run = factory.createR();

        p.getParagraphContent().add(run);        
        Drawing drawing = factory.createDrawing();      
        run.getRunContent().add(drawing);       
        drawing.getAnchorOrInline().add(inline);

        return p;
    }

This is the code i am using for drawing an image to word using docx4j.

beauXjames
  • 8,222
  • 3
  • 49
  • 66
  • Is that message the entire output from your program when run on the Linux server? To me, that message suggests that there has already been an error, i.e. before that exception was thrown the JVM had already tried and failed to load the BinaryPartAbstractImage class. Does your application have any logs on the Linux server? If so, look in those logs to see if you can find a previous error. – Luke Woodward Jan 02 '15 at 18:48
  • Can you supply your command line used, and what your "local machine" OS is? If you're local machine is Windows, and you're using `java -classpath jar1.jar;jar2.jar`, then you need to change the semi-colons (`;`) to (`:`) colons on the Linux server – Alex Jan 03 '15 at 06:05
  • My local machine is Windows OS...I configured my docx4j jar both local and Linux server as like other jar in manifest file with space like jar1.jar jar2.jar – Vijay Marudhachalam Jan 03 '15 at 06:13
  • Luke, i don't have any specific exception about BinaryPartAbstractImage class on my Linux server but one more exception occurred before this because of jaxb jar is missing... Please see the below log. INFO org.docx4j.jaxb.Context - loaded com.ibm.xml.xlxp2.jaxb.JAXBContextImpl .. loading others .. ERROR org.docx4j.jaxb.Context - Cannot initialize context javax.xml.bind.JAXBException: "org.plutext.jaxb.xmldsig" doesnt contain ObjectFactory.class or jaxb.index – Vijay Marudhachalam Jan 03 '15 at 06:46
  • The problematic bit seems to be here: `com.common.cmd.htmltodoc.newImage`. No idea what that's about, but two things to note with the image classes in docx4j: (1) you need the apache xmlgraphics package on your classpath and (2) I recall some tweaks required when it comes to linux and Java AWT classes. I'll see if I can remember more... – Ben Jan 04 '15 at 13:12
  • i have xmlgraphics-commons-1.3.1.jar on my classpath – Vijay Marudhachalam Jan 05 '15 at 06:23
  • From your earlier comment, you are missing jaxb-xmldsig-core-1.0.0.jar (and probably other jars as well...) – JasonPlutext Jan 05 '15 at 07:17
  • @VijayMarudhachalam list the JAR files you have on your server as dependencies for docx4j. It sounds like you're missing one or more. – Ben Jan 06 '15 at 09:23
  • docx4j-2.8.1.jar, org-apache-commons-logging.jar, org.apache.commons.io.jar, xmlgraphics-commons-1.5.jar, jaxb-xmldsig-core-1.0.0.jar. These are JAR in my class path. Is there any other specific jar need for linux server machine. The same jar is also in local machine but there is no error in my local machine. – Vijay Marudhachalam Jan 07 '15 at 14:13
  • i think awt.jar is not there in linux platform.. where to instal awt.jar in web websphere server installed in linux machine – Vijay Marudhachalam Jan 09 '15 at 07:18
  • Caused by: java.lang.NoClassDefFoundError: com.vwa.BinaryPartAbstractImage (initialization failure) at java.lang.J9VMInternals.initialize(J9VMInternals.java:140) at com.ibm._jsp._HtmlToDoc._jspService(_HtmlToDoc.java:125) ... 30 more Caused by: java.awt.HeadlessException at sun.awt.HeadlessToolkit.getScreenResolution(HeadlessToolkit.java:215) at org.apache.xmlgraphics.image.loader.impl.DefaultImageContext.(DefaultImageContext.java:37) at com.vwa.BinaryPartAbstractImage.(BinaryPartAbstractImage.java:127) at java.lang.J9VMInternals.initializeImpl(Native Method) – Vijay Marudhachalam Jan 09 '15 at 07:21
  • Please look at org.apache.xmlgraphics.image.loader.impl.DefaultImageContext this class there are referencing awt methods anf getting error on the same line . – Vijay Marudhachalam Jan 09 '15 at 07:23

0 Answers0