RAPIDMINER 9.7 BETA ANNOUNCEMENT

The beta program for the RapidMiner 9.7 release is now available. Lots of amazing new improvements including true version control!

CLICK HERE TO DOWNLOAD

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

polluxpollux Member Posts: 3 Contributor I
edited May 2019 in Help
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.

Tagged:

Answers

  • steffensteffen Member Posts: 347  Guru
    Hi pollux,

    Back then carol aka chaney ignored by begging to give me feedback on the modified groovy operator, so I did not bother anymore, too. But now that you are here ... Frankly, I was a little lazy and didn't test it with the groovy http module itself.

    So I will definitely have a look at it, but not before sunday (so little time, so much to code). If you are still working on this issue, please post everything you find out ;).

    greetings,

    steffen
  • polluxpollux Member Posts: 3 Contributor I
    Hi Steffen,

    Thanks for the quick update.

    To be more precise about my testing of your GroovyScripting operator, I have installed it as a plugin in a fresh RM 5.1 installation, and tried it with the sample process you've included in your post (the one using the commons-math-2.1 library).

    This sample mathlab process doesn't compile, Groovy inside RM says it is unable to resolve class org.apache.commons.math.stat.descriptive.DescriptiveStatistics

    Unfortunately I've neither the time nore the immediate knowledge to investigate deeper by myself the class loading problem :'(, but if you manage to solve it I'll be happy to test and give feedback.

    best regards

    pollux
  • steffensteffen Member Posts: 347  Guru
    Hi pollux

    I am verrry sorry for the late reply ... the last two weeks I was really grateful that there is some time left where I do not have to stare at a monitor (aka my free time) ;).

    1. My plugins works within rm5.1, the process with apache commons math, too. Are you sure that you have pointed the parameter to the correct location of the library ?
    2. The grab-functionality is around since groovy 1.6.0, so this should not be an issue. However, notice that rm5.1 uses groovy 1.6.3 (< current version).

    So ... this seems to be a bug happening when the classloader magic of groovy,maven and rm collide. Since I do not even have a maven installation on my home computer, I will need some time to investigate.

    Sorry again for the late reply and for not-providing a fix

    greetings,

    steffen
  • steffensteffen Member Posts: 347  Guru
    Ok ...

    The reason seems to be the groovy version. Although groovy grape has been introduced around 1.6.2-BETA, the syntax (among other things) have changed since then. Since I really did not want to download a bunch of outdated software to find a fix , here is my advice for the latest groovy version.
    • Download the latest groovy zip file and replace the groovy-all.jar under rapidminer/lib/ with the groovy-all-1.7.7,jar
    • Additionally download apache ivy (http://ant.apache.org/ivy/download.cgi) and place ivy-2.2.0.jar in the same folder. Reason: An bug/"undesired behavior" of grape (see here)
    • now start rapidminer using the startup-script, i.e. either rapidminer/scripts/RapidMinerGUI.bat (windows) or rapidminer/scripts/RapidminerGUI (linux). Now the execute-script operator together with your groovy-httpbuilder-script should work (at least it worked for me)
    All in all the grab-functionality is really cool. It is much better than my proposed modification (the one drawback is that you need maven installation).

    on a sidenote: I added a feature request for this, so hopefully grape will work in 5.2+

    regards,

    steffen

  • polluxpollux Member Posts: 3 Contributor I
    Hi Steffen,

    Thanks for the answer.

    I gave it a try and made some progress (Grape classes are loading), but now I come into the Ivy "bug" you mentioned, despite having ivy-2.2.0.jar in the RM classpath when starting with RapidMinerGUI.bat.

    Anyway I managed to workaround my "real world" process problem without using Groovy, so I can live without it until 5.2+...

    Thanks for adding a feature request for 5.2+,  it'll unleash the full power of the RM/Groovy combination.

    Best

    Pollux
Sign In or Register to comment.