How to run a groovy file which include other groovy files please?
I have three groovy file: /my.groovy, /my_dir/util.groovy, /my_dir/base.groovy
my.groovy:
def shell = new GroovyShell()
def util = shell.parse(new File("my_dir/util.groovy"))
println(util.run());
util.groovy:
def getName(String name)
def base = new base();
return name * base.getTimes();
println(getName('hi,'));
base.groovy:
def getTimes()
return 20;
Now I run groovy my.groovy, and it can not work because unable to resolve class base. If these files all in the same dir, it can work. How to do it in this case please? (with no compile)
groovy
add a comment |
I have three groovy file: /my.groovy, /my_dir/util.groovy, /my_dir/base.groovy
my.groovy:
def shell = new GroovyShell()
def util = shell.parse(new File("my_dir/util.groovy"))
println(util.run());
util.groovy:
def getName(String name)
def base = new base();
return name * base.getTimes();
println(getName('hi,'));
base.groovy:
def getTimes()
return 20;
Now I run groovy my.groovy, and it can not work because unable to resolve class base. If these files all in the same dir, it can work. How to do it in this case please? (with no compile)
groovy
add a comment |
I have three groovy file: /my.groovy, /my_dir/util.groovy, /my_dir/base.groovy
my.groovy:
def shell = new GroovyShell()
def util = shell.parse(new File("my_dir/util.groovy"))
println(util.run());
util.groovy:
def getName(String name)
def base = new base();
return name * base.getTimes();
println(getName('hi,'));
base.groovy:
def getTimes()
return 20;
Now I run groovy my.groovy, and it can not work because unable to resolve class base. If these files all in the same dir, it can work. How to do it in this case please? (with no compile)
groovy
I have three groovy file: /my.groovy, /my_dir/util.groovy, /my_dir/base.groovy
my.groovy:
def shell = new GroovyShell()
def util = shell.parse(new File("my_dir/util.groovy"))
println(util.run());
util.groovy:
def getName(String name)
def base = new base();
return name * base.getTimes();
println(getName('hi,'));
base.groovy:
def getTimes()
return 20;
Now I run groovy my.groovy, and it can not work because unable to resolve class base. If these files all in the same dir, it can work. How to do it in this case please? (with no compile)
groovy
groovy
asked Nov 15 '18 at 12:18
xunitcxunitc
437
437
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
A.groovy
def b=new B()
println b.greet("world")
./mydir/B.groovy
def greet(n)
return "hello $n"
assume you are in the directory where A.groovy located
how to run:
groovy -cp ./mydir/ A.groovy
in this case you are running class A
and specifying to lookup other classes from directory ./mydir/
or you can use packages:
A.groovy
import mydir.*
def b=new B()
println b.greet("world")
./mydir/B.groovy
package mydir
def greet(n)
return "hello $n"
how to run:
groovy -cp . A.groovy
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319366%2fhow-to-run-a-groovy-file-which-include-other-groovy-files-please%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A.groovy
def b=new B()
println b.greet("world")
./mydir/B.groovy
def greet(n)
return "hello $n"
assume you are in the directory where A.groovy located
how to run:
groovy -cp ./mydir/ A.groovy
in this case you are running class A
and specifying to lookup other classes from directory ./mydir/
or you can use packages:
A.groovy
import mydir.*
def b=new B()
println b.greet("world")
./mydir/B.groovy
package mydir
def greet(n)
return "hello $n"
how to run:
groovy -cp . A.groovy
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
add a comment |
A.groovy
def b=new B()
println b.greet("world")
./mydir/B.groovy
def greet(n)
return "hello $n"
assume you are in the directory where A.groovy located
how to run:
groovy -cp ./mydir/ A.groovy
in this case you are running class A
and specifying to lookup other classes from directory ./mydir/
or you can use packages:
A.groovy
import mydir.*
def b=new B()
println b.greet("world")
./mydir/B.groovy
package mydir
def greet(n)
return "hello $n"
how to run:
groovy -cp . A.groovy
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
add a comment |
A.groovy
def b=new B()
println b.greet("world")
./mydir/B.groovy
def greet(n)
return "hello $n"
assume you are in the directory where A.groovy located
how to run:
groovy -cp ./mydir/ A.groovy
in this case you are running class A
and specifying to lookup other classes from directory ./mydir/
or you can use packages:
A.groovy
import mydir.*
def b=new B()
println b.greet("world")
./mydir/B.groovy
package mydir
def greet(n)
return "hello $n"
how to run:
groovy -cp . A.groovy
A.groovy
def b=new B()
println b.greet("world")
./mydir/B.groovy
def greet(n)
return "hello $n"
assume you are in the directory where A.groovy located
how to run:
groovy -cp ./mydir/ A.groovy
in this case you are running class A
and specifying to lookup other classes from directory ./mydir/
or you can use packages:
A.groovy
import mydir.*
def b=new B()
println b.greet("world")
./mydir/B.groovy
package mydir
def greet(n)
return "hello $n"
how to run:
groovy -cp . A.groovy
edited Nov 15 '18 at 13:29
answered Nov 15 '18 at 13:07
daggettdaggett
8,93521530
8,93521530
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
add a comment |
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
Thank you. I know it, I can use getClass() and get path in util.groovy to find the base.groovy. but I do not think it is an elegant solution. I means like python, just import file and can use the methods in that file. Could groovy do it?
– xunitc
Nov 15 '18 at 13:14
updated answer...
– daggett
Nov 15 '18 at 13:29
updated answer...
– daggett
Nov 15 '18 at 13:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319366%2fhow-to-run-a-groovy-file-which-include-other-groovy-files-please%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown