【发布时间】:2012-04-07 08:43:15
【问题描述】:
当我尝试使用来自外部 JAR 的库时,我遇到了 Grails 2.0 中 NoClassDefFound 异常的问题。
我已经检查了声明的 JAR 是否在创建的 WAR 中,grials 的依赖报告也没有标记任何问题。
本地添加的 JAR 或从 Maven 存储库下载似乎没有区别。我也尝试过清理 IVY 缓存和清理 grails 项目,但没有成功。
您有任何解决方法的想法吗?
BuildConfig.groovy(部分)
grails.project.dependency.resolution = {
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
mavenLocal()
mavenRepo "http://snapshots.repository.codehaus.org"
mavenRepo "http://repository.codehaus.org"
mavenRepo "http://download.java.net/maven/2/"
mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
compile ( "javax:activation:1.0",
"javax:mail:1.0",
"com.google.gdata:gdata-core:1.0",
"com.google.gdata:gdata-client:1.0",
"com.google.gdata:gdata-media:1.0",
"com.google.gdata:gdata-youtube:2.0"
)
runtime ( "javax:activation:1.0",
"javax:mail:1.0",
"com.google.gdata:gdata-core:1.0",
"com.google.gdata:gdata-client:1.0",
"com.google.gdata:gdata-media:1.0",
"com.google.gdata:gdata-youtube:2.0"
)
}
...
}
LibraryController.groovy
import com.google.gdata.client.youtube.YouTubeService
import com.google.gdata.data.youtube.VideoEntry
import com.google.gdata.util.ServiceException
class LibraryController {
private YouTubeService service
private static final API_URL = "http://gdata.youtube.com/feeds/api/videos/"
def index = {
service = new YouTubeService("app")
}
}
例外
Class
java.lang.NoClassDefFoundError
Message
Could not initialize class com.google.gdata.client.youtube.YouTubeServiceClass
java.lang.NoClassDefFoundError
消息 无法初始化 com.google.gdata.client.youtube.YouTubeService 类
【问题讨论】:
-
我通常只使用 'jar -tf' 来检查 war 文件中的 jar 文件,以确保包含类文件 YouTubeServiceClass。
-
什么时候出现这个错误?在运行时使用
run-app? -
是的,我正在使用运行应用程序,进入库视图时出现异常。
-
我在任何存储库中都找不到 javax:mail:1.0。确定不是 javax.mail:mail?
-
我也没有在任何回购中找到谷歌罐子。它们是否手动安装到您的本地 Maven 缓存中?是否使用了 4 个自定义 maven 存储库?
标签: grails groovy dependencies noclassdeffounderror buildconfig