我正在尝试使用jruby语言执行JSR223
如果我放置普通的String可以工作,但是我不能将JMeter预定义变量用作log
log.info("Hello from JRuby");
无法找到log
:
2019-07-11 17:27:30,078 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:104) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:93) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:133) ~[jruby-core-1.7.27.jar:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
Caused by: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:132) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90) ~[jruby-core-1.7.27.jar:?]
... 8 more
Caused by: org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `log' for main:Object
at RUBY.(root)(<script>:1) ~[?:?]
我在jruby wiki on JSR个示例中发现前缀为@variableName
的变量
engine.put(“ @ name”,“樱花”);
但是对于@log
,我得到了不同的错误(因为它为Nil / Null)
javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method
info'for nil:NilClass`
可以克服它还是无法在JMeter的JSR223中运行jruby?
答案 0 :(得分:0)
JRuby实际上可以使用$
前缀找到预定义的变量:
$log.info("Hello from JRuby");