为Groovy安装HTTPBuilder [英] Installing HTTPBuilder for Groovy
问题描述
对于新手问题抱歉,但是如何为Groovy安装HTTPBuilder?
我添加了http-builder-0.7.jar,http-builder- 0.7-source.jar和http-builder-0.7-javadoc.jar到GROOVY_HOME / lib。
还有什么我需要做的吗? HTTPBuilder网站不清楚。
从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')
我得到这个回应:
groovy.lang.MissingMethodException:没有签名方法:static groovy.grape.Grape.grab()适用于参数类型:(java.lang.String,java.lang.String,java.lang.String)values:[org.codehaus.groovy.modules.http- (java.lang.String),grep(),grab(java.util.Map),grab(java.util.Map,[Ljava.util。地图;),等待(),转储()
编辑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')
响应:
java.lang.NoClassDefFoundError:org / apache / http / client / methods / HttpRequestBase
在ConsoleScript6.run(ConsoleScript6:4)
引起:java.lang.ClassNotFoundException:org.apache.http.client.methods.HttpRequestBase
... 1 more
为我开箱即用:
@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
您需要删除直接添加到GROOVY_HOME \lib的任何依赖关系jar。手动添加罐子可能会产生冲突并导致这些类型的错误。检查是否已手动将HttpClient库添加到库中,并将它们移除并重试。
编辑:使用IntelliJ ,我已经能够重现这种行为一次。我已经将一个 @Grab
注释添加到我的Groovy脚本中。首先,如果添加第二个 @ @ 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')
])
之后,我在这里找到了我的解决方案: Intellij IDEA不从Groovy项目中的@Grab导入依赖关系,这与使用IntelliJ时遇到此问题相比有所解释,尝试将光标放在 @Grapes
注释旁边并选择 Alt + Enter ,然后选择 '的Gr ab Artifacts' 选项。
Apologies for the newbie question, but how do you install HTTPBuilder for Groovy?
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.
Is there anything else I need to do? The HTTPBuilder website isn't clear.
Code run from 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:
@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. Manually adding the jars there could create conflicts and cause these types of errors. Check to see if you have manually added the HttpClient libraries to the lib, remove them as well and try again.
EDIT: When using IntelliJ, I have been able to reproduce this behavior once. I already had a single @Grab
annotation added to my Groovy script. 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):
@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.
这篇关于为Groovy安装HTTPBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!