【发布时间】:2011-09-11 16:03:32
【问题描述】:
如何在 Grails 中安装和使用 httpbuilder 插件?
【问题讨论】:
-
没有名为“httpbuilder”的插件。不过有一个REST Client 插件。在documentation 中是否有关于它的安装或使用不清楚的地方?您的问题相当广泛。
标签: grails groovy httpbuilder
如何在 Grails 中安装和使用 httpbuilder 插件?
【问题讨论】:
标签: grails groovy httpbuilder
将 httpbuilder 0.5.1 添加到您的应用程序依赖项将导致错误。特别是,您会收到如下错误:
java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.xerces.jaxp.SAXParserImpl.getParser()Lorg/xml/sax/Parser;" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/xerces/jaxp/SAXParserImpl, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Parser used in the signature
我认为问题在于 httpbuilder 将其编译时依赖项导出为运行时依赖项。一个简单的解决方法是在 BuildConfig.groovy 中声明这样的依赖项:
grails.project.dependency.resolution = {
...
dependencies {
runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.1') {
excludes 'xalan'
excludes 'xml-apis'
excludes 'groovy'
}
}
}
我认为您在存储库部分也需要mavenRepo "http://repository.codehaus.org"。
【讨论】:
安装:
grails install-plugin rest
例子:
withHttp(uri: "http://www.google.com") {
def html = get(path : '/search', query : [q:'Groovy'])
assert html.HEAD.size() == 1
assert html.BODY.size() == 1
}
【讨论】:
get替换为post
install-plugin can no longer be used to install plugins。我现在还在想办法解决这个问题,我真的很想念 node/npm :(
我最终使用了 ataylor 的上述步骤,但随后注释掉了该块并测试了插件:
compile ":rest:0.7"
Rest 插件使用 http-builder 并且没有上述依赖项,我的应用程序仍然可以正常工作并通过 http builder 进行调用。
【讨论】: