简体   繁体   English

为Groovy安装HTTPBuilder

[英]Installing HTTPBuilder for Groovy

Apologies for the newbie question, but how do you install HTTPBuilder for Groovy? 对新手问题表示歉意,但是如何为Groovy安装HTTPBuilder?

I've added the http-builder-0.7.jar, http-builder-0.7-source.jar, and http-builder-0.7-javadoc.jar to GROOVY_HOME/lib. 我已经将http-builder-0.7.jar,http-builder-0.7-source.jar和http-builder-0.7-javadoc.jar添加到GROOVY_HOME / lib中。

Is there anything else I need to do? 还有什么我需要做的吗? The HTTPBuilder website isn't clear. HTTPBuilder网站尚不清楚。

Code run from GroovyConsole: 代码从GroovyConsole运行:

import groovy.grape.Grape

Grape.grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')

I get this in response: 我得到了回应:

groovy.lang.MissingMethodException: No signature of method: static groovy.grape.Grape.grab() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [org.codehaus.groovy.modules.http-builder, http-builder, 0.7]
Possible solutions: grab(java.lang.String), grep(), grab(java.util.Map), grab(java.util.Map, [Ljava.util.Map;), wait(), dump()

EDIT 2: 编辑2:

 @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

 def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')

Response: 响应:

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase

at ConsoleScript6.run(ConsoleScript6:4)

Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase

... 1 more

The following example works for me out of the box: 以下示例适用于我开箱即用:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')
println http

You need to remove any of the dependency jars you added directly to GROOVY_HOME\\lib. 您需要删除直接添加到GROOVY_HOME \\ lib的任何依赖项jar。 Manually adding the jars there could create conflicts and cause these types of errors. 手动添加jar可能会产生冲突并导致这些类型的错误。 Check to see if you have manually added the HttpClient libraries to the lib, remove them as well and try again. 检查是否已将HttpClient库手动添加到lib中,同时将其删除并重试。

EDIT: When using IntelliJ, I have been able to reproduce this behavior once. 编辑:使用IntelliJ时,我已经能够重现这种行为一次。 I already had a single @Grab annotation added to my Groovy script. 我已经在我的Groovy脚本中添加了一个@Grab注释。 When I added a second, it didn't seem to download or import the new library. 当我添加第二个时,它似乎没有下载或导入新库。

First of all, if you add a second @Grab , you need to wrap it in the @Grapes annotation like the following (my first mistake): 首先,如果你添加第二个@Grab ,你需要将它包装在@Grapes注释中,如下所示(我的第一个错误):

@Grapes([
        @Grab(group='org.codehaus.gpars', module='gpars', version='1.2.1'),
        @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
])

After that, I found my solution here: Intellij IDEA not importing dependencies from @Grab in Groovy project , which explains than when using IntelliJ and you encounter this issue, try placing your cursor next to the @Grapes annotation and selecting Alt+Enter then choose the 'Grab the Artifacts' option. 在那之后,我在这里找到了我的解决方案: Intellij IDEA没有在Groovy项目中导入来自@Grab的依赖项 ,这解释了比使用IntelliJ时遇到此问题,尝试将光标放在@Grapes注释旁边并选择Alt + Enter然后选择'Grab the Artifacts'选项。

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

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