Zobbl
Zobbl

Reputation: 479

Grails: Provide a library to an external groovy script

what I have: an external GroovyScript using the apache-commons-io library

and a working grails application

In the existing grails-application there are different external scripts (as of now only perl-scripts) which are executed async with grails (using the execute-Method).

Now I got an GroovyScript which I want to run the same way as I run the PerlScripts.

At the moment the script has the commons-io-library in a lib-folder. It works fine.

So my question is: How do I provide the groovy-script with the commons-io-library from grails in a smooth and neat way? Do I have to provide the path within the command which is executed via the execute-Method

e.g.:

groovy -cp=path/to/grailshome/lib.jar scripfile.groovy

this won't really work if I deploy the grailsapplication to the tomcat in the current production-environment as the libs from grails are in a different path.

Putting the script into the src/groovy folder of grails would probably work, but that's not the way I want it. The script needs to be standalone.

I'm really stuck as I'm not really versed with the technical details of and groovy grails.

Even suggestions and ideas how this can be accomplished are enough.

I hope you understand the question, thanks in advance

Upvotes: 1

Views: 577

Answers (1)

tim_yates
tim_yates

Reputation: 171194

Is this a situation where using Grapes and putting:

@Grab( 'commons-io:commons-io:2.1' )

At the top of your groovy script would help?

If you are running this as a war, then this might work:

String path = grailsApplication.parentContext
                               .getResource( 'WEB-INF/lib/commons-io-1.4.jar' )
                               .file
                               .absolutePath

Upvotes: 1

Related Questions