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

Java 如何将外部库(libs)集成到grails项目中?,java,grails,groovy,intellij-idea,htmlunit,Java,Grails,Groovy,Intellij Idea,Htmlunit,我有一个新的Grails2.0项目,我想将HtmlUnit库集成到其中。 我刚刚将HtmlUnit 2.9 libs移动到grails项目的“lib”文件夹中,并在grails服务中使用它们。当我使用Intellij11IDE启动应用程序时,它不会启动,因为grails找不到导入 在我的服务课上,我做到了: import com.gargoylesoftware.htmlunit.WebClient import com.gargoylesoftware.htmlunit.BrowserVe

我有一个新的Grails2.0项目,我想将HtmlUnit库集成到其中。 我刚刚将HtmlUnit 2.9 libs移动到grails项目的“lib”文件夹中,并在grails服务中使用它们。当我使用Intellij11IDE启动应用程序时,它不会启动,因为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项目中?

是否将jar添加到构建路径?

是否将jar添加到构建路径?

与其将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'
    }
}

不要将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'
    }
}

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

dependencies {

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

如果不生效,可以先清理grails ivy缓存,然后重试。

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

dependencies {

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

如果不生效,可以先清理grails ivy缓存,然后重试。

这就是问题所在。在eclipse/sts中有一个名为“buildpath”的contextoption。我在intelliJ中找不到类似的选项。或者我必须在其他地方编辑构建路径吗?这与您看到的不同,但它们在这里解释了如何进行编辑,嗯……我不是idea用户,所以我无法使用它。这些包中使用的其他类是否会给您带来麻烦?也许只是.jar…当我在没有IDE的情况下使用普通grails时,它应该可以工作吗?我想使用sts/eclipse,但最新的Grails2.0还不受支持。应该可以。我在grails开发中使用netbeans,这非常好。虽然我只使用插件来使用功能,但我不确定这是否有助于解决您的问题,但在grails中使用HtmlUnit时,似乎不应该在类路径中包含xml API-*.jar。这就是问题所在。在eclipse/sts中有一个名为“buildpath”的contextoption。我在intelliJ中找不到类似的选项。或者我必须在其他地方编辑构建路径吗?这与您看到的不同,但它们在这里解释了如何进行编辑,嗯……我不是idea用户,所以我无法使用它。这些包中使用的其他类是否会给您带来麻烦?也许只是.jar…当我在没有IDE的情况下使用普通grails时,它应该可以工作吗?我想使用sts/eclipse,但最新的Grails2.0还不受支持。应该可以。我在grails开发中使用netbeans,这非常好。虽然我只使用插件来使用功能..不确定这是否有助于解决您的问题,但当您将HtmlUnit与grails一起使用时,似乎不应该在类路径中包含xml API-*.jar。HtmlUnit的依赖项必须具有“编译”范围,因为它用于非测试代码中。HtmlUnit的依赖项必须具有“编译”范围,因为它在非测试代码中使用。