🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

"Unable to use @Grab in Groovy script to add maven dependencies to classpath"

User: "pollux"
New Altair Community Member
Updated by Jocelyn
Hi,

I want to use the "Execute Script" RM operator to run a Groovy script using the HTTPBuilder module.

The Groovy script uses @Grab to add the required dependencies and runs perfectly in the GroovyConsole.

But when I run it from the RapidMiner UI in the "Execute Script" operator, I get the following error :

Process failed:
The scripting engine Groovy reported an error in the script: org.codehaus.groovy.control.
MultipleCompilationErrorsException: startup failed, Script1.groovy: 8: unexpected token: import @ line 8, column 1.
1 error

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.001">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.1.001" expanded="true" name="Process">
    <process expanded="true" height="684" width="884">
      <operator activated="true" class="execute_script" compatibility="5.1.001" expanded="true" height="60" name="Execute Script" width="90" x="255" y="165">
        <parameter key="script" value="@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )&#10;import groovyx.net.http.*&#10;import static groovyx.net.http.ContentType.*&#10;import static groovyx.net.http.Method.*&#10;&#10;def http = new HTTPBuilder( 'http://ajax.googleapis.com' )&#10;&#10;// perform a GET request, expecting JSON response data&#10;http.request( GET, JSON ) {&#10;  uri.path = '/ajax/services/search/web'&#10;  uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]&#10;&#10;  headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'&#10;&#10;  // response handler for a success response code:&#10;  response.success = { resp, json -&gt;&#10;    println resp.statusLine&#10;&#10;    // parse the JSON response object:&#10;    json.responseData.results.each {&#10;      println &quot;  ${it.titleNoFormatting} : ${it.visibleUrl}&quot;&#10;    }&#10;  }&#10;&#10;  // handler for any failure status code:&#10;  response.failure = { resp -&gt;&#10;    println &quot;Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}&quot;&#10;  }&#10;}"/>
      </operator>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
    </process>
  </operator>
</process>
Any fix or workaround available ?

NB: I also tried to use the modified execute script plugin proposed by Steffen in another post but it didn't work either.

Find more posts tagged with