groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edinson E. PadrĂ³n Urdaneta <edinson.padron.urdan...@gmail.com>
Subject [Apache POI] java.lang.NoClassDefFoundError
Date Thu, 20 Aug 2015 02:06:40 GMT
Greetings everyone,

I have the following java class:

package gpg;

import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.xwpf.usermodel.*;

class Parse {
    public static void main(String[] args) throws IOException {
        FileInputStream documentFile = new FileInputStream(/* filename */);
        XWPFDocument document = new XWPFDocument(documentFile);

        for (IBodyElement element: document.getBodyElements()) {
            if (element.getElementType() == BodyElementType.TABLE) {
                XWPFTable currentTable = (XWPFTable) element;

                for (XWPFTableRow row: currentTable.getRows()) {
                    System.out.print("(\n    0");
                    for (XWPFTableCell cell: row.getTableCells()) {
                        System.out.print(',');
                        System.out.print("\"" + cell.getText() + "\"");
                    }
                    System.out.print("\n),");
                }
            }
        }

        document.close();
    }
}

It compiles and runs without any problem but its Groovy version (without
any change, beside the file extension) throws a
`java.lang.NoClassDefFoundError` exception described below:

* groovy:

Caught: java.lang.NoClassDefFoundError:
[Lorg/openxmlformats/schemas/wordprocessingml/x2006/main/CTCustomXmlRun;
java.lang.NoClassDefFoundError:
[Lorg/openxmlformats/schemas/wordprocessingml/x2006/main/CTCustomXmlRun;
        at gpg.Parse.main(Parse.groovy:17)
Caused by: java.lang.ClassNotFoundException:
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTCustomXmlRun
        ... 1 more


* groovyc and then java:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/openxmlformats/schemas/wordprocessingml/x2006/main/CTCustomXmlRun
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetPublicMethods(Class.java:2902)
        at java.lang.Class.getMethods(Class.java:1615)
        at
org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.getSAMMethod(CachedSAMClass.java:161)
        at
org.codehaus.groovy.reflection.ClassInfo.isSAM(ClassInfo.java:356)
        at
org.codehaus.groovy.reflection.ClassInfo.createCachedClass(ClassInfo.java:346)
        at
org.codehaus.groovy.reflection.ClassInfo.access$700(ClassInfo.java:38)
        at
org.codehaus.groovy.reflection.ClassInfo$LazyCachedClassRef.initValue(ClassInfo.java:494)
        at
org.codehaus.groovy.reflection.ClassInfo$LazyCachedClassRef.initValue(ClassInfo.java:485)
        at
org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
        at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
        at
org.codehaus.groovy.reflection.ClassInfo.getCachedClass(ClassInfo.java:108)
        at
org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:107)
        at
org.codehaus.groovy.reflection.ParameterTypes.getParametersTypes0(ParameterTypes.java:78)
        at
org.codehaus.groovy.reflection.ParameterTypes.getParameterTypes(ParameterTypes.java:64)
        at
org.codehaus.groovy.runtime.metaclass.MetaMethodIndex.isMatchingMethod(MetaMethodIndex.java:450)
        at
org.codehaus.groovy.runtime.metaclass.MetaMethodIndex.addMethodToList(MetaMethodIndex.java:375)
        at
groovy.lang.MetaClassImpl.addMetaMethodToIndex(MetaClassImpl.java:2950)
        at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:366)
        at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:341)
        at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3261)
        at
org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:251)
        at
org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:282)
        at
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:255)
        at
org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:872)
        at
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:84)
        at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
        at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232)
        at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:244)
        at gpg.Parse.main(Parse.groovy:17)
Caused by: java.lang.ClassNotFoundException:
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTCustomXmlRun
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 31 more

My classpath:

/home/nodxine/.groovy/grapes/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.1.jar:/home/nodxine/.groovy/grapes/org.apache.poi/poi-ooxml-schemas/jars/poi-ooxml-schemas-3.13-beta1.jar:/home/nodxine/.groovy/grapes/org.apache.poi/poi-ooxml/jars/poi-ooxml-3.13-beta1.jar:/home/nodxine/.groovy/grapes/org.apache.poi/poi/jars/poi-3.13-beta1.jar:/home/nodxine/.groovy/grapes/org.apache.xmlbeans/xmlbeans/jars/xmlbeans-2.6.0.jar:.

I've searched the internet for a workaround or an explanation without any
luck. Every answer was related to xmlbeans not been in the classpath but
that's no the case here. I'm very curious about what's going on.

Thanks in advance for your time.

Mime
View raw message