繁体   English   中英

如何将外部库(lib)集成到grails项目中?

[英]How to integrate external librarys (libs) into a grails project?

我有一个新的grails 2.0项目,我想将HtmlUnit-Libraries集成到其中。 我只是将HtmlUnit 2.9库移动到了grails项目的“ lib”文件夹中,并在grails-service中使用了它们。 当我使用intelliJ 11 IDE启动应用程序时,它不会启动,因为grails找不到导入。

在我的服务班里,我做了:

 import com.gargoylesoftware.htmlunit.WebClient
 import com.gargoylesoftware.htmlunit.BrowserVersion

启动grails运行应用程序脚本后,出现以下异常:

/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项目中?

与其将jar复制到/lib目录中, BuildConfig.groovy尝试在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'
    }
}

我遇到了同样的问题,已经解决了。 在BuildConfig.groovy中指定它。

dependencies {

    compile('net.sourceforge.htmlunit:htmlunit:2.9') {
        excludes 'xml-apis' 
    }
}

如果未生效,则可以先清理grails常春藤缓存,然后重试。

您是否将罐子添加到构建路径?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM