Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFoundException: org.docx4j.openpackaging.exceptions.Docx4JException

So here we go again. My head is banging on my PC about few hours, I can't figured out what to do. On my local PC I run the java code from Intellij Idea. It works. Now I have to create jar file to make it able to use on some remote server. I added all libraries, jars that my program needs at project settings (Added libraries at Artifacts section). But it doesn't work running at remote server. What imports my program needs:

import org.docx4j.dml.CTBlip;
import org.docx4j.jaxb.XPathBinderAssociationIsPartialException;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.PartName;
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
import org.docx4j.relationships.Relationship;

import javax.xml.bind.JAXBException;
import java.io.File;
import java.util.List;

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/docx4j/openpackaging/exceptions/Docx4JException
Caused by: java.lang.ClassNotFoundException: org.docx4j.openpackaging.exceptions.Docx4JException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: Main. Program will exit.

So is the problem in creating the jar? I missed something?

like image 383
Daria Avatar asked Oct 20 '22 11:10

Daria


2 Answers

org.docx4j.openpackaging.exceptions.Docx4JException is in the docx4j.jar file, so make sure that (and all docx4j's dependencies) is on your classpath.

like image 134
JasonPlutext Avatar answered Oct 29 '22 00:10

JasonPlutext


I faced with a similar issue when original docx4j jars were not loaded by a classloader.

I tried these ones:

  • docx4j-3.1.0.jar
  • docx4j-3.2.1.jar

For some reason, Midnight Commander couldn't open them (by enter pressing) from the first attempt and reported "Inconsistent extfs archive". The problem was solved by the jar recreation

# run in a directory containing just single original docx4j jar file
unzip docx4j-3.2.1.jar
rm -r docx4j-3.2.1.jar
jar cf docx4j-3.2.1.jar *

Now the new jar is opened in MC without problems (at least in my case) and its classes are loaded and java.lang.NoClassDefFoundError is not thrown anymore.

UPDATE

JIC, I just checked which JDK the jar I used belong to.

It is OpenJDK 64-Bit 1.7.0_79, Linux Mint 17.

like image 20
humkins Avatar answered Oct 29 '22 00:10

humkins