If the libraries are stored in a Maven repository that is accessible wherever you want to run it, one solution would be to use Grape to grab the libraries.
This provides several benefits:
- You don't have to worry about the classpath at all
- You don't have to distribute the libraries — just make sure Groovy is available on the client
- Libraries are downloaded just once, so even if you upgrade the application, you only have to redistribute the
.groovy file.
A simple example:
#!/usr/bin/env groovy
@Grab(group='commons-io', module='commons-io', version='2.3')
import org.apache.commons.io.FileUtils
... use FileUtils like normal ...
There's a lot of existing libraries available on mvnrepository.com already.
Even if you have non-public libraries, it's relatively easy to put your own libraries into a local / private repository.
dirname $0