我有一个新的grails 2.0项目,我想将HtmlUnit-Libraries集成到它中。 我只是将HtmlUnit 2.9库移动到我的grails项目的“lib”-Folder中,并在我的grails-service中使用它们。当我使用intelliJ 11 IDE启动我的应用程序时,它无法启动,因为grails无法找到导入。
在我的服务课中,我做了:
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.BrowserVersion
启动grails run-app脚本后,我得到以下异常:
/Users/whitenexx/Workspaces/sts-workspace/OMTool/grails-app/services/omtool/TestService.groovy: 4: unable to resolve class com.gargoylesoftware.htmlunit.BrowserVersion
@ line 4, column 1.
import com.gargoylesoftware.htmlunit.BrowserVersion^
如何将java库集成到grails项目中?
答案 0 :(得分:4)
不要将jar复制到/lib
目录中,而是尝试在BuildConfig.groovy
中指定它
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
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()
mavenLocal()
mavenCentral()
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile 'net.sourceforge.htmlunit:htmlunit:2.9'
}
}
答案 1 :(得分:1)
您是否已将jar添加到构建路径中?
答案 2 :(得分:1)
我遇到了同样的问题,已经解决了。在BuildConfig.groovy中指定它。
dependencies {
compile('net.sourceforge.htmlunit:htmlunit:2.9') {
excludes 'xml-apis'
}
}
如果没有生效,你可以先清理你的grails ivy-cache然后再试一次。