如何解决Grails编译中的NoClassDefFoundError?

时间:2017-05-31 12:39:07

标签: java grails gradle imap

我正在将项目从Grails 1.3.7升级到3.2.6。我有类导入IMAPFolder和IMAPProtocol之类的东西。我相信这需要我将com.sun.mail:imap包含为编译时依赖项。我在build.gradle中有这个:

compile group: 'com.sun.mail', name: 'imap', version: '1.5.6'

但是,当我添加并尝试编译时,我收到Java编译错误。

General error during conversion: java.lang.NoClassDefFoundError: com/sun/mail/util/ReadableMime

java.lang.RuntimeException: java.lang.NoClassDefFoundError: com/sun/mail/util/ReadableMime
        at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1089)
        at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1067)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:525)
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:173)
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:59)
        at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:31)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoClassDefFoundError: com/sun/mail/util/ReadableMime
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:545)
        at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:185)
        at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:170)
        at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:126)
        at org.codehaus.groovy.control.ResolveVisitor.resolveToOuter(ResolveVisitor.java:676)
        at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:308)
        at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1218)
        at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:176)
        at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit$1.call(JavaAwareCompilationUnit.java:71)
        at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1053)
    ... 24 more Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.ReadableMime
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 46 more

我如何通过这个? imap库没有显示任何其他编译依赖项,所以我不知道该怎么做。

2 个答案:

答案 0 :(得分:0)

IMAPFolderIMAPProtocol是JavaMail API的一部分。

你应该添加

compile group: 'javax.mail', name: 'mail', version: '1.4.7'

而不是

compile group: 'com.sun.mail', name: 'imap', version: '1.5.6'

您可能需要另一个版本see here

答案 1 :(得分:0)

感谢您的建议。我在那里有javax.mail的依赖,但更高版本。

我实际上今天早上刚刚解决了这个问题。事实证明,我需要javax.mail版本1.4.3(或左右,但至少1.4.3工作)和Sun imap 1.4.3 jar。 Gradle无法从任何地方拉出imap-1.4.3.jar,所以我在本地下载了它,终于很开心了。

所以有javax.mail的建议和不同版本的建议都是现货。

compile files('lib/imap-1.4.3.jar')
compile group: 'javax.mail', name: 'mail', version: '1.4.3'