I tried renaming that Java file from the front page of the project to .groovy, and then run it with the jar of the library on the classpath, but I used the -d flag for having some more verbose output. And the results below are strange, as if the annotation classes from that library jar had some issue of some sort and the groovy compiler wouldn't find them in the jar (although they seem to be):
glaforge-mbp:tmp glaforge$ groovy -d -cp ~/Downloads/cltool4j.jar Jgrep
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/Jgrep.groovy: 5: unable to resolve class BaseCommandlineTool
<at> line 5, column 1.
public class Jgrep extends BaseCommandlineTool {
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class BaseCommandlineTool
<at> line 5, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:232)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:228)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1168)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
/private/tmp/Jgrep.groovy: 7: unable to resolve class Option , unable to find class for annotation
<at> line 7, column 5.
<at> Option(name = "-C", metaVar = "lines", usage = "Print lines of context following a match")
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Option , unable to find class for annotation
<at> line 7, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
/private/tmp/Jgrep.groovy: 11: unable to resolve class Option , unable to find class for annotation
<at> line 11, column 5.
<at> Option(name = "-i", usage = "invert match")
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Option , unable to find class for annotation
<at> line 11, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
/private/tmp/Jgrep.groovy: 16: unable to resolve class Argument , unable to find class for annotation
<at> line 16, column 5.
<at> Argument(index = 0, required = true, metaVar = "pattern")
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class Argument , unable to find class for annotation
<at> line 16, column 5.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.visitAnnotations(ResolveVisitor.java:1042)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitField(ClassCodeExpressionTransformer.java:63)
at org.codehaus.groovy.control.ResolveVisitor.visitField(ResolveVisitor.java:178)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1176)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$9.call(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:903)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:566)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:515)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:204)
at groovy.lang.GroovyShell.run(GroovyShell.java:150)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:557)
at groovy.ui.GroovyMain.run(GroovyMain.java:344)
at groovy.ui.GroovyMain.process(GroovyMain.java:330)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:119)
at groovy.ui.GroovyMain.main(GroovyMain.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
4 errors
On Tue, Oct 9, 2012 at 2:11 PM, Scholz. Ulrich
<u.scholz <at> seeburger.de> wrote:
Hi Guillaume, thanks for pointing to CliBuilder. I will ask for it in a separate thread.
Yes, I was trying to use the class Jgrep as given on the web page. I created a groovy class in Eclipse, copied the code, and ran it with Run
as > Groovy script.
Then the error appears but no stack trace. Nothing else.
Java: 1.6.0_33
Groovy: 2.0.2
Best, Ulrich
Von: Guillaume Laforge [mailto:glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org]
Gesendet: Montag, 8. Oktober 2012 15:23
An: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
Betreff: Re: [groovy-user] Groovy and cltool4j: Unable to instantiate target class
[…]
On Mon, Oct 8, 2012 at 3:16 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Hi Ulrich,
Perhaps you give the version of Java, of Groovy, that you are using. Also the full stacktrace might be good.
And when you say you tried the example, this is the big example we see on the link you posted below?
Guillaume
On Mon, Oct 8, 2012 at 3:06 PM, Scholz. Ulrich <u.scholz <at> seeburger.de> wrote:
Dear all,
I’d like to use Groovy to write own shell commands. To ease the command definition, I’d like to use cltool4j, “a simple framework intended to speed development of command-line tools in Java.“
Now, If I run the cltool4j example (on the website
http://code.google.com/p/cltool4j/) as Java application, it works fine. But if I run it as Groovy script (with ending .groovy) I get
Unable to instantiate target class: sun.reflect.NativeMethodAccessorImpl.<init>()
Why that? Thanks, Ulrich
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
...
| SEEBURGER AG |
|
Vorstand/Seeburger Executive Board: |
| Sitz der Gesellschaft/Registered Office: |
|
Bernd Seeburger, Axel Haas, Michael Kleeberg |
| Edisonstr. 1 |
|
|
| D-75015 Bretten |
|
Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board: |
| Tel.: 07252 / 96 - 0 |
|
Dr. Franz Scherer |
| Fax: 07252 / 96 - 2222 |
|
|
| Internet: http://www.seeburger.de
|
|
Registergericht/Commercial Register: |
| e-mail: info-dFjtzhuVO4pM7kwft8N7nw@public.gmane.org
|
|
HRB 240708 Mannheim |
Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder
Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift
oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.
The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily
the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being
your own responsibility to check this email and its attachments for this purpose.
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one