tags:

views:

42

answers:

2

I have my java code running.

I added a groovy shell to evaluate the main groovy file.

What it does is simple. GroovyShell.run (main.groovy)

Now, in my main.groovy, if I have other .groovy files I'd like to "require", how can I do that?

Is there something like "require, source, load, require_one, import" filename?

A: 

http://groovy.codehaus.org/Embedding+Groovy

if you scroll down to the section entitled "Dynamically loading and running Groovy code inside Java" you will see a full example with two different approaches to solving your problem

Aaron Saunders
A: 

Actually, here is the answer:

I couldn't find a function like that in Groovy.

So, when evaluating your file, you have to parse all groovy files.

If you add new files on the fly and would like to evaluate them, you can't reuse the shell, not even through a singleton via the evaluated script

What you can do is register your parsed files and force the shell to "re-parse" them all again when re-evaluating your file.

hbt