So it looks like groovy picks up groovy scripts from the current directory
by default.
So the users can't just do "/path/to/scripts/TagText.groovy <myfile>" any
more.
They would have to do:
cd /path/to/scripts/
./TagText.groovy <myfile>

or they would have to invoke groovy explicitly:
groovy -cp /path/to/scripts /path/to/scripts/TagText.groovy <myfile>



On Fri, Mar 4, 2022 at 7:04 AM Jochen Theodorou <blackd...@gmx.org> wrote:

> On 12.02.22 17:03, Andriy Rysin wrote:
> > Hi all
> >
> > I have a question about running/packaging groovy programs.
> > I have a small suite of (commandline) NLP tools
> > (https://github.com/brown-uk/nlp_uk
> > <https://github.com/brown-uk/nlp_uk>) that is often used by
> > non-developers (NLP students, researches etc).
> > When the scripts where simple it was very easy to run them:
> > 1) install groovy
> > 2) git clone/pull
> > 3) then you run scripts from anywhere with simple
> > ..../nlp_uk/src/main/groovy/org/nlp_uk/tools/TagText.groovy -i
> > input_file.txt
> >
> > The dependencies are pulled via grape, the command is simple to run and
> > update.
> >
> > Now scripts got some common parallelization code and I extracted common
> > code into TextUtils but to keep things still simple I just use:
> >    Eval.me(new File("$SCRIPT_DIR/TextUtils.groovy") .....
> > for a simple "include" hack.
>
> Let us assume TagText.groovy and TextUtils.groovy are in
> nlp_uk/src/main/groovy/org/nlp_uk/tools. Let us further assume, that
> TextUtils.groovy is a class and has a method extractTags(). Then you can
> do just "new TextUtils().extractTags()" in TagText and Groovy will try
> to resolve the class TextUtils by itself, leading to loading (and
> compiling on the fly) TextUtils.groovy and to execute the extractTags
> method from there.
>
> So all you need to do is to put the TextUtils file in a path Groovy can
> find (on the classpath) as well as make it a class. If you want to work
> with packages, then the file needs to be in a sub directory that fits to
> the package naming scheme.
>
> This will also pick up a change in TextUtils and TagText, since nothing
> is precompiled.
>
> If you do not want to work with instances of TextUtils, you can make the
> methods static and then do something like TextUtils.extractTags(). or
> you do "import static TextUtils.extractTags" to import the method and
> then just call it with "extractTags()"
>
> does this help?
>
> bye Jochen
>
>

Reply via email to