I have a groovy script that uses a third party library. Each time I open the application and attempt to run my script I have to import the proper library.
I would like to be able to open GroovyConsole and run my application without having to import the library.
You can write an external Groovy script that does all the imports, creates a GroovyConsole object, and calls the run() method on this object.
See also http://groovy.codehaus.org/Groovy+Console#GroovyConsole-EmbeddingtheConsole
For example: start.groovy
From a shell script call the groovy executable providing it with the groovy script:
The code in GroovyConsole can now make use of the imports done in start.groovy, as well as of the variables created and passed with the setVariable method ('service' in the example).
At least on Linux groovy GroovyConsole is a Script has the Following command:
startGroovy itself is a script which starts Java. Within the startGroovy script you should be able to modify your classpath and add the missing librarys.
From startGroovy:
If you are on a Mac, I would highly recommend using SDKMAN to manage Groovy installations.
Once installed via SDKMAN, you can modify
~/.sdkman/candidates/groovy/current/bin/groovy/conf/groovy-starter.conf
. Packages you add here will be automatically imported at runtime whenever you start a Groovy Console session. You would want to add them under the section labelled in the example below:If you just want to add the JARs to the classpath, copy (or symlink) them to
~/.groovy/lib
(or%USER_HOME%/.groovy/lib
on Windows).If you want the actual
import
statements to run every time Groovy Console starts, edit the groovy-starter.conf file as suggested by Squelsh.In Linux you also have
Here you can add your specific libs:
Hope it helps, had to search long time to find this (: