|
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? |
|
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 |
|
Administrator
|
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? |
|
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 |
|
Administrator
|
IoUtils is compiled from Java. I know it should work because I have similar scripts in BeanShell and Pnuts that use IoUtils and work. |
|
> 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 |
|
Administrator
|
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 . |
|
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 |
|
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: |
|
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 |
|
Jochen
You win :-) but actually I tried to reproduce his problem and successfully got the same error. What could be wrong ? Cheers Tog bye blackdrag |
|
tog schrieb:
> Jochen > > will not produce something usefull.. maybe: > > import fschmidt.util.java.* > println(IoUtils); > > but I guess the result will be a MissingPropertyException > > You win :-) > > but actually I tried to reproduce his problem and successfully got the > same error. > What could be wrong ? I am using a comparable setup in my IDE and I have no problems, so I am not sure what is wrong. Executed directly via GroovyMain means that no RootLoader is involved, only the normal GroovyClassLoader, so if the class is on the ClassPath it should compile. 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 |
|
Administrator
|
Could you please try running it from the command line without any Groovy-specific environment variables set? All you need to do is to run: java groovy.ui.GroovyMain t.groovy where t.groovy should refer to some class file in your classpath. |
|
In reply to this post by fschmidt
I'm having similar problems (on Mac OS X) trying to use a java music jar file:
$ env | grep CLASSPATH CLASSPATH=/Users/bslade/Library/Groovy // Note, I softlinked the Groovy .jar files into this dir. It maybe uneccessary, but it shouldn't hurt anything: $ ls -l /Users/bslade/Library/Groovy lrwxr-xr-x 1 bslade bslade 39 Apr 30 00:18 commons-cli-1.0.jar -> /Library/Groovy/lib/commons-cli-1.0.jar lrwxr-xr-x 1 bslade bslade 45 Apr 30 00:30 groovy-all-1.0.jar -> /Library/Groovy/embeddable/groovy-all-1.0.jar -rw-r--r-- 1 bslade bslade 97335 Apr 29 23:52 jfugue.jar $ cat jfugue_demo.groovy import org.jfugue.*; Player player = new Player(); Pattern pattern = new Pattern("C D E F G A B"); player.play(pattern); // This *should* use the CLASSPATH env variable, but... $ groovyc jfugue_demo.groovy org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, jfugue_demo.groovy: 6: unable to resolve class Player ...snip... // But if I explicitly specify the jar file, it *does* compile: $ groovyc -classpath $CLASSPATH/jfugue.jar jfugue_demo.groovy // But then when I try and run it, it give errors similar to fschmidt's: $ java jfugue_demo Exception in thread "main" java.lang.NoClassDefFoundError: jfugue_demo // Same result when I explicitly state class/jar locations: $ java -cp "$GROOVY_HOME/embeddable/groovy-all-1.0.jar;$GROOVY_HOME/lib/commons-cli-1.0.jar;$CLASSPATH/jfugue.jar" jfugue_demo Exception in thread "main" java.lang.NoClassDefFoundError: jfugue_demo Interestingly, if I change the filename of the class that is supposed to be run, it gives the same error message (with the new classname): $ java xxx Exception in thread "main" java.lang.NoClassDefFoundError: xxx So it looks like it's not finding the class file I just compiled (which was created). I hope this doesn't turn out to be something incredibly obvious ;) Thanks in advance Ben Slade benslade.com
|
|
bslade schrieb:
> I'm having similar problems (on Mac OS X) trying to use a java music jar > file: > > $ env | grep CLASSPATH > CLASSPATH=/Users/bslade/Library/Groovy > > // Note, I softlinked the Groovy .jar files into this dir. It maybe > uneccessary, but it shouldn't hurt anything: > $ ls -l /Users/bslade/Library/Groovy > lrwxr-xr-x 1 bslade bslade 39 Apr 30 00:18 commons-cli-1.0.jar > -> /Library/Groovy/lib/commons-cli-1.0.jar > lrwxr-xr-x 1 bslade bslade 45 Apr 30 00:30 groovy-all-1.0.jar > -> /Library/Groovy/embeddable/groovy-all-1.0.jar > -rw-r--r-- 1 bslade bslade 97335 Apr 29 23:52 jfugue.jar hmm... I don't remember clearly but unless the it is now possible to put directories containing jars in the classpath, this is no valid classpath... At last in java5 the jars would not be used. I don't know your version on Mac, but this seems to be no groovy but a java problem. > $ cat jfugue_demo.groovy > import org.jfugue.*; > Player player = new Player(); > Pattern pattern = new Pattern("C D E F G A B"); > player.play(pattern); > > // This *should* use the CLASSPATH env variable, but... > $ groovyc jfugue_demo.groovy > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup > failed, jfugue_demo.groovy: 6: unable to resolve class Player > ...snip... won't work for groovyc, groovyc needs the classic classpath way... so you ahve to list all jars. > // But if I explicitly specify the jar file, it *does* compile: > $ groovyc -classpath $CLASSPATH/jfugue.jar jfugue_demo.groovy > > // But then when I try and run it, it give errors similar to fschmidt's: > $ java jfugue_demo > Exception in thread "main" java.lang.NoClassDefFoundError: jfugue_demo > > // Same result when I explicitly state class/jar locations: > $ java -cp > "$GROOVY_HOME/embeddable/groovy-all-1.0.jar;$GROOVY_HOME/lib/commons-cli-1.0.jar;$CLASSPATH/jfugue.jar" > jfugue_demo > Exception in thread "main" java.lang.NoClassDefFoundError: jfugue_demo ok, but that's another exception. You need to add "." as well, how else should java find the class? > Interestingly, if I change the filename of the class that is supposed to be > run, it gives the same error message (with the new classname): > $ java xxx > Exception in thread "main" java.lang.NoClassDefFoundError: xxx well if there is no xxx.class file somewhere it is no wonder. > So it looks like it's not finding the class file I just compiled (which was > created). I hope this doesn't turn out to be something incredibly obvious > ;) incredibly obvious ^^ 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 |
|
In reply to this post by bslade
I think I know how to use any .jar file within your compiling line:
e.g if you wanna add one, or more than one, jar library: $ javac -classpath .:jfugue.jar:xalan.jar:xerces.jar YOURJAVAFILE.java & to run it : $ java -classpath .:jfugue.jar:xalan.jar:xerces.jar YOURJAVAFILE "without . java" But , how to set that path forever? I have no idea :P I hope that I helped here :)
![]()
|
| Powered by Nabble | Edit this page |
