NoClassDefFound 尝试使用 grails 控制器中的 java 类和 docx4j
我有一个 groovy 文件,它试图从我使用 docx4j 设置的 Java 类中调用一些方法来解析 .docx 文件
当我在 eclipse 中设置纯 java 测试程序时,我能够很好地做到这一点。但是,当我设置 .groovy 文件时,我没有得到任何编译错误,但在运行时我得到了这个堆栈跟踪:
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org/docx4j/wml/RPr
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
Caused by: java.lang.NoClassDefFoundError: org/docx4j/wml/RPr
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:33)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:20)
at ResumeController$_closure8.doCall(ResumeController.groovy:119)
at ResumeController$_closure8.doCall(ResumeController.groovy)
我不太清楚问题是什么 - 这是 groovy 文件的相关部分
import mypackage.DocxHelpers.DocxParser;
import org.docx4j.*;
class ResumeController{
def save = {
File f=new File('c:/dev/temp/test.docx');
uploadedFile.transferTo(f);
DocxParser doc=new DocxParser(); //line 119
def resume=doc.openDocx4j(f);
f.delete();
resumeInstance.entireResume=resume;
flash.message="Resume parsed";
render(view:'create',model:[resumeInstance:resumeInstance]);
}
}
:与DocxParser相关的java内容位于我的项目文件夹下的src文件夹中,docx4j jar位于lib文件夹中。
我是否只是错误地定义了导入,或者文件位于错误的位置?
I have a groovy file that is trying to call some methods from a Java class that I have set up using docx4j to parse .docx files
When I set up a pure java test program in eclipse, I am able to do this fine. However, when I have my .groovy file set up, I get no compilation errors, but at runtime I get this stack trace:
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org/docx4j/wml/RPr
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
Caused by: java.lang.NoClassDefFoundError: org/docx4j/wml/RPr
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:33)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:20)
at ResumeController$_closure8.doCall(ResumeController.groovy:119)
at ResumeController$_closure8.doCall(ResumeController.groovy)
I can't quite figure out what the problem is - here is the relevant portion of thre groovy file:
import mypackage.DocxHelpers.DocxParser;
import org.docx4j.*;
class ResumeController{
def save = {
File f=new File('c:/dev/temp/test.docx');
uploadedFile.transferTo(f);
DocxParser doc=new DocxParser(); //line 119
def resume=doc.openDocx4j(f);
f.delete();
resumeInstance.entireResume=resume;
flash.message="Resume parsed";
render(view:'create',model:[resumeInstance:resumeInstance]);
}
}
My java stuff related to DocxParser is in the src folder under my project folder, and the docx4j jar is in the lib folder.
Do I simply have my imports defined incorrectly, or are the files in the wrong place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的运行时类路径中似乎没有 docx4j JAR。上面的代码似乎属于 Grails 控制器。您是否检查过
NoClassDefFoundError
引用的类是否存在于 Grails/lib
目录中的docx4j
JAR 中?It looks like you don't have the
docx4j
JARs on your runtime classpath. The code above seems to belong to a Grails controller. Have you checked that the class referred to by theNoClassDefFoundError
is present within thedocx4j
JAR(s) in the Grails/lib
directory?看起来找不到的类位于 org.docx4j.wml 包中,但 import 语句引用了 org.docx4j 包。尝试将导入更改为
import org.docx4j.wml.*;
。It looks like that class that isn't found is in the org.docx4j.wml package, but the import statement refers to org.docx4j package. Try changing the import to
import org.docx4j.wml.*;
.