Due to recent updates, all users are required to create an Altair One account to login to the RapidMiner community. Click the Register button to create your account using the same email that you have previously used to login to the RapidMiner community. This will ensure that any previously created content will be synced to your Altair One account. Once you login, you will be asked to provide a username that identifies you to other Community users. Email us at Community with questions.
"Unable to use @Grab in Groovy script to add maven dependencies to classpath"
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
NB: I also tried to use the modified execute script plugin proposed by Steffen in another post but it didn't work either.
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
Any fix or workaround available ?
<?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' ) import groovyx.net.http.* import static groovyx.net.http.ContentType.* import static groovyx.net.http.Method.* def http = new HTTPBuilder( 'http://ajax.googleapis.com' ) // perform a GET request, expecting JSON response data http.request( GET, JSON ) { uri.path = '/ajax/services/search/web' uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ] headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4' // response handler for a success response code: response.success = { resp, json -> println resp.statusLine // parse the JSON response object: json.responseData.results.each { println " ${it.titleNoFormatting} : ${it.visibleUrl}" } } // handler for any failure status code: response.failure = { resp -> println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}" } }"/>
</operator>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
</process>
</operator>
</process>
NB: I also tried to use the modified execute script plugin proposed by Steffen in another post but it didn't work either.
Tagged:
0
Answers
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
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
best regards
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
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
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