Quantcast

running Groovy from java command line

classic Classic list List threaded Threaded
16 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

running Groovy from java command line

fschmidt
Administrator
I want to run Groovy from Java from the command line without shell scripts.  I copied groovy-all-1.0.jar into jre/lib/ext and tried:

> java org.codehaus.groovy.tools.GroovyStarter t.groovy
no configuration file or main class specified

> java groovy.ui.GroovyMain t.groovy
java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
Exception in thread "main"

How do I do this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

paulk_asert
fschmidt wrote:

> I want to run Groovy from Java from the command line without shell scripts.
> I copied groovy-all-1.0.jar into jre/lib/ext and tried:
>
>> java org.codehaus.groovy.tools.GroovyStarter t.groovy
> no configuration file or main class specified
>
>> java groovy.ui.GroovyMain t.groovy
> java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
> Exception in thread "main"
>
> How do I do this?
>

You need commons cli on your classpath.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

fschmidt
Administrator
Paul King wrote
fschmidt wrote:
> I want to run Groovy from Java from the command line without shell scripts.

You need commons cli on your classpath.
Thank you, that worked.

Now I get:

unable to resolve class fschmidt.util.java.IoUtils

My import statement is:

import fschmidt.util.java.IoUtils;

IoUtils is implemented in a class file in my classpath.  What is wrong?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

Alasdair-2
fschmidt wrote:
> Now I get:
>
> unable to resolve class fschmidt.util.java.IoUtil
Hi,

It's hard to give useful comments without more info. Is your IoUtil
class java src or Groovy? (the path to it suggests it's Java). have you
compiled it? can you see the .class file in the correct directory and is
your classpath setup to include the directory above fschmidt?

Suggest adding a 'Hello world' main() method to your IoUtil class and
check that you can invoke it using the same classpath as you're using
for your programme. If you can't then either your classpath is wrong or
your .class file isn't where it should be.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

fschmidt
Administrator
Alasdair-2 wrote
fschmidt wrote:
> Now I get:
>
> unable to resolve class fschmidt.util.java.IoUtils

Is your IoUtil class java src or Groovy?

Suggest adding a 'Hello world' main() method to your IoUtil class and
check that you can invoke it using the same classpath as you're using
for your programme.
IoUtils is compiled from Java.  I know it should work because I have similar scripts in BeanShell and Pnuts that use IoUtils and work.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

Alasdair-2

> IoUtils is compiled from Java.  I know it should work because I have similar
> scripts in BeanShell and Pnuts that use IoUtils and work.
>  
Without more information about your setup I can't really help. I think
you'll need to give a detailed description of your setup so that others
can understand exactly what's happening. Maybe create a simplified test
case to demonstrate the problem?

Alasdair

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

fschmidt
Administrator
Alasdair-2 wrote
Without more information about your setup I can't really help. I think
you'll need to give a detailed description of your setup so that others
can understand exactly what's happening. Maybe create a simplified test
case to demonstrate the problem?

I copied groovy-all-1.0.jar and commons-cli-1.0.jar into jre/lib/ext .  I created a file t.groovy containing:

import fschmidt.util.java.IoUtils;
println("hello");

(This is just a minimal test.)  Then I tried running it with:

java groovy.ui.GroovyMain t.groovy

and got:

unable to resolve class fschmidt.util.java.IoUtils

IoUtils.class was compiled from Java and is accessible through my classpath.  I use it in Java programs and from scripts in BeanShell and Pnuts without problems.

I am using cygwin and java 1.5 .
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

Jochen Theodorou
fschmidt schrieb:
[...]

> import fschmidt.util.java.IoUtils;
> println("hello");
>
> (This is just a minimal test.)  Then I tried running it with:
>
> java groovy.ui.GroovyMain t.groovy
>
> and got:
>
> unable to resolve class fschmidt.util.java.IoUtils

and you are sure it is on the classpath? you have a CLASSPATH variable
set? I guess, because you are not using the -cp option. What happens if
you add the classpath using the -cp option instead of using CLASSPATH?

bye blackdrag

--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

tog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

tog
Hi
Can you tell me how things are going when importing  fschmidt.util.java.* ?
Thanks
Tog

On 4/29/07, Jochen Theodorou <[hidden email]> wrote:
fschmidt schrieb:
[...]

> import fschmidt.util.java.IoUtils ;
> println("hello");
>
> (This is just a minimal test.)  Then I tried running it with:
>
> java groovy.ui.GroovyMain t.groovy
>
> and got:
>
> unable to resolve class fschmidt.util.java.IoUtils

and you are sure it is on the classpath? you have a CLASSPATH variable
set? I guess, because you are not using the -cp option. What happens if
you add the classpath using the -cp option instead of using CLASSPATH?

bye blackdrag

--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: running Groovy from java command line

Jochen Theodorou
tog schrieb:
> Hi
> Can you tell me how things are going when importing  fschmidt.util.java.* ?

such an import is not resolved, so something like:
[...]
>      > import fschmidt.util.java.IoUtils ;
>      > println("hello");

will not produce something usefull.. maybe:

  import fschmidt.util.java.*
  println(IoUtils);

but I guess the result will be a MissingPropertyException

bye blackdrag


--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

12
Loading...