views:

94

answers:

2

I am working on a grails project and I have put a .jar file in the lib directory of the project.

I keep getting a runtime exception for ClassNotFoundException in one of my java files that I am using in the grails project.

I have a method defined as such:

void printValues(org.docx4j.wml.ParaRPr rpr){
}

and I have and import section that looks like

 import org.docx4j.openpackaging.exceptions.Docx4JException;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
 import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
 import org.docx4j.wml.Body;
 import org.docx4j.wml.Style;

This is what is throwing the exception.

However, if I change my method to be like

void printValues(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart rpr){
}

I get no runtime exception.

What could possibly be going on here? I have verified that the docx4j.jar file contains ParaRPr, and it does. I have verified that those classes are public,and they are. Also, I have tried different classes from the org.docx4j.wml directory, and some give me the exception, and some dont. How is this even possible?

Here is the full stacktrace:

 2010-09-15 12:37:00,198 [http-8080-1] ERROR errors.GrailsExceptionResolver  - org.docx4j.wml.ParaRPr
 java.lang.ClassNotFoundException: org.docx4j.wml.ParaRPr
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
    at java.lang.Class.getDeclaredMethods(Class.java:1791)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at javatest.ResumeController$_closure4.doCall(ResumeController.groovy:47)
    at javatest.ResumeController$_closure4.doCall(ResumeController.groovy)
    at java.lang.Thread.run(Thread.java:619)
   [groovyc] Compiling 1 source file to C:\dev\JavaTest\target\classes

Here is the output of jar -tf on the jar file - showing the ParaRPr class in there

$ jar -tf docx4j-nightly-20100914.jar  | grep Para
org/docx4j/dml/CTTextParagraph.class
org/docx4j/dml/CTTextParagraphProperties.class
org/docx4j/dml/diagram/CTParameter.class
org/docx4j/dml/diagram/STParameterId.class
org/docx4j/math/CTOMathPara.class
org/docx4j/math/CTOMathParaPr.class
org/docx4j/model/properties/paragraph/AbstractParagraphProperty.class
org/docx4j/wml/CTParaRPrOriginal.class
org/docx4j/wml/ParaRPr.class
org/docx4j/wml/ParaRPrChange.class
org/pptx4j/pml/CTTLBuildParagraph.class
org/pptx4j/pml/CTTLTimeNodeParallel.class
org/pptx4j/pml/STTLParaBuildType.class
org/xlsx4j/sml/CTParameter.class
org/xlsx4j/sml/CTParameters.class
org/xlsx4j/sml/STParameterType.class
+1  A: 

Yould could be missing a jar on which docx4j.jar depends.

Maurice Perry
+1: Although the ClassNotFound exception should note that - it should say something like "Error loading class org.docx4j.wml.ParaRPr - could not find dependency X" or something similar (exact syntax is escaping me at the moment).
aperkins
Hrmm, I would have thought so as well. I just posted stacktrace.
Derek
It would seem like if I can see the files it is complaining about within the .jar, then it should be ok, right?
Derek
Unfortunately, java doesn't tell which dependency is missing
Maurice Perry
Does this still make sense if I can look into docx4j.jar and see the file that is specifically referenced in the stack trace?
Derek
I deal with this kind of issue by adding jars one by one until I get no more errors
Maurice Perry
Note that I have done a program that lists all the dependencies of a class to answer another question, here: http://stackoverflow.com/questions/3437426/getting-full-classpath-from-a-class/3437580#3437580
Maurice Perry
+1  A: 

docx4j has a number of dependencies as described here: http://dev.plutext.org/trac/docx4j/wiki/Docx4jDependencies

It looks like ParaRPr implements Child which is in org.jvnet.jaxb2_commons I believe your runtime environment is missing the jar that has Child

Doyle
Thats exactly what it was. Good call. Now I know how to start debugging this stuff in the future
Derek