You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by RJ <ss...@gmail.com> on 2017/05/22 17:40:58 UTC

Simple question.. how to call a java class method in Groovy Script

Here is my script. Highlighted the method call.. tried some google searches
for the syntax. Thanks for the help!

import java.util.*
import com.example.auth.user;

class EBSAttrRelease {
    def Map<UserString, List<UserObject>> run(final UserObject... args) {
    def userid=com.example.auth.user.getId()
    return [MYLOGINID:userid]
    }
}

Error:
2017-05-22 13:32:56,986 ERROR - <groovy.lang.MissingMethodException: No
signature of method: static com.example.auth.user.getId() is applicable for
argument types: () values: []
Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
wait(long), grep(java.lang.Object)>

Re: Simple question.. how to call a java class method in Groovy Script

Posted by Keith Suderman <su...@anc.org>.
I recommend JetBrains IntelliJ to everyone.  If you are a student you can get the Ultimate edition for free, the free "community" version is typically sufficient for most use cases, and purchasing an Ultimate Edition license will pay for itself in a few weeks in a corporate environment.

Cheers,
Keith

> On May 22, 2017, at 4:31 PM, RJ <ss...@gmail.com> wrote:
> 
> I'm working on the server directly.. any suggestions on IDE for groovy script ? Thanks
> 
> 
> On Mon, May 22, 2017 at 3:43 PM, Keith Suderman <suderman@anc.org <ma...@anc.org>> wrote:
> 
>> On May 22, 2017, at 2:13 PM, RJ <ssoguroo@gmail.com <ma...@gmail.com>> wrote:
>> 
>> Thanks for the response, Jochen.  Tried your suggestion, it doesn't like it:
>> 
>> 2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No signature of method: static com.example.auth.principal.getId() is applicable for argument types: () values: []
>> Possible solutions: getAt(java.lang.String), wait(), find(), grep(), wait(long), grep(java.lang.Object)>
>> org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.example.auth.principal.getId() is applicable for argument types: () values: []
>> Possible solutions: getAt(java.lang.String), wait(), find(), grep(), wait(long), grep(java.lang.Object)
> 
> Is the class name Principal or principal? Also, what IDE are you using?  Any decent IDE should be able to show you the available method signatures and do auto-completion for you.
> 
>> 
>> We try something like this in Java.. Whats the equivalent in Groovy Script ?
> 
> Whenever in doubt just use the Java syntax.  Apart from some Java 8 stuff (coming soon), Groovy is perfectly happy with Java syntax.  Once the code is working then you can worry about making it more "Groovy"
> 
> Cheers,
> Keith
> 
>> 
>> import com.example.auth.principal;
>> public String1 abcd(final principal Principal){
>> return Principal.getId();
>> }
>> 
>> On Mon, May 22, 2017 at 2:03 PM, Jochen Theodorou <blackdrag@gmx.org <ma...@gmx.org>> wrote:
>> On 22.05.2017 19 <tel:22.05.2017%2019>:40, RJ wrote:
>> Here is my script. Highlighted the method call.. tried some google
>> searches for the syntax. Thanks for the help!
>> 
>> import java.util.*
>> import com.example.auth.user;
>> 
>> class EBSAttrRelease {
>>      def Map<UserString, List<UserObject>> run(final UserObject... args) {
>>      def userid=com.example.auth.user.getId()
>>      return [MYLOGINID:userid]
>>      }
>> }
>> 
>> try "import com.example.auth.user as User" instead of "import com.example.auth.user" and then "def userid=User.getId()"... assuming of course that getId is a static method in the class com.example.auth.user
>> 
>> bye Jochen
>> 
> 
> ----------------------
> Keith Suderman
> Research Associate
> Department of Computer Science
> Vassar College, Poughkeepsie NY
> suderman@cs.vassar.edu <ma...@cs.vassar.edu>
> 
> 
> 
> 
> 

----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY
suderman@cs.vassar.edu





Re: Simple question.. how to call a java class method in Groovy Script

Posted by RJ <ss...@gmail.com>.
I'm working on the server directly.. any suggestions on IDE for groovy
script ? Thanks


On Mon, May 22, 2017 at 3:43 PM, Keith Suderman <su...@anc.org> wrote:

>
> On May 22, 2017, at 2:13 PM, RJ <ss...@gmail.com> wrote:
>
> Thanks for the response, Jochen.  Tried your suggestion, it doesn't like
> it:
>
> 2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No
> signature of method: static com.example.auth.principal.getId() is
> applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)>
> org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException:
> No signature of method: static com.example.auth.principal.getId() is
> applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)
>
>
> Is the class name Principal or principal? Also, what IDE are you using?
> Any decent IDE should be able to show you the available method signatures
> and do auto-completion for you.
>
>
> We try something like this in Java.. Whats the equivalent in Groovy Script
> ?
>
>
> Whenever in doubt just use the Java syntax.  Apart from some Java 8 stuff
> (coming soon), Groovy is perfectly happy with Java syntax.  Once the code
> is working then you can worry about making it more "Groovy"
>
> Cheers,
> Keith
>
>
> import com.example.auth.principal;
> public String1 abcd(final principal Principal){
> return Principal.getId();
> }
>
> On Mon, May 22, 2017 at 2:03 PM, Jochen Theodorou <bl...@gmx.org>
> wrote:
>
>> On 22.05.2017 19:40, RJ wrote:
>>
>>> Here is my script. Highlighted the method call.. tried some google
>>> searches for the syntax. Thanks for the help!
>>>
>>> import java.util.*
>>> import com.example.auth.user;
>>>
>>> class EBSAttrRelease {
>>>      def Map<UserString, List<UserObject>> run(final UserObject... args)
>>> {
>>>      def userid=com.example.auth.user.getId()
>>>      return [MYLOGINID:userid]
>>>      }
>>> }
>>>
>>
>> try "import com.example.auth.user as User" instead of "import
>> com.example.auth.user" and then "def userid=User.getId()"... assuming of
>> course that getId is a static method in the class com.example.auth.user
>>
>> bye Jochen
>>
>
>
> ----------------------
> Keith Suderman
> Research Associate
> Department of Computer Science
> Vassar College, Poughkeepsie NY
> suderman@cs.vassar.edu
>
>
>
>
>

Re: Simple question.. how to call a java class method in Groovy Script

Posted by Keith Suderman <su...@anc.org>.
> On May 22, 2017, at 2:13 PM, RJ <ss...@gmail.com> wrote:
> 
> Thanks for the response, Jochen.  Tried your suggestion, it doesn't like it:
> 
> 2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No signature of method: static com.example.auth.principal.getId() is applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(), wait(long), grep(java.lang.Object)>
> org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.example.auth.principal.getId() is applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(), wait(long), grep(java.lang.Object)

Is the class name Principal or principal? Also, what IDE are you using?  Any decent IDE should be able to show you the available method signatures and do auto-completion for you.

> 
> We try something like this in Java.. Whats the equivalent in Groovy Script ?

Whenever in doubt just use the Java syntax.  Apart from some Java 8 stuff (coming soon), Groovy is perfectly happy with Java syntax.  Once the code is working then you can worry about making it more "Groovy"

Cheers,
Keith

> 
> import com.example.auth.principal;
> public String1 abcd(final principal Principal){
> return Principal.getId();
> }
> 
> On Mon, May 22, 2017 at 2:03 PM, Jochen Theodorou <blackdrag@gmx.org <ma...@gmx.org>> wrote:
> On 22.05.2017 19 <tel:22.05.2017%2019>:40, RJ wrote:
> Here is my script. Highlighted the method call.. tried some google
> searches for the syntax. Thanks for the help!
> 
> import java.util.*
> import com.example.auth.user;
> 
> class EBSAttrRelease {
>      def Map<UserString, List<UserObject>> run(final UserObject... args) {
>      def userid=com.example.auth.user.getId()
>      return [MYLOGINID:userid]
>      }
> }
> 
> try "import com.example.auth.user as User" instead of "import com.example.auth.user" and then "def userid=User.getId()"... assuming of course that getId is a static method in the class com.example.auth.user
> 
> bye Jochen
> 

----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY
suderman@cs.vassar.edu





Re: Simple question.. how to call a java class method in Groovy Script

Posted by Jochen Theodorou <bl...@gmx.org>.
On 22.05.2017 20:13, RJ wrote:
> Thanks for the response, Jochen.  Tried your suggestion, it doesn't like it:
>
> 2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No
> signature of method: static com.example.auth.principal.getId() is
> applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)>
> org.codehaus.groovy.runtime.InvokerInvocationException:
> groovy.lang.MissingMethodException: No signature of method: static
> com.example.auth.principal.getId() is applicable for argument types: ()
> values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
> wait(long), grep(java.lang.Object)
>
> We try something like this in Java.. Whats the equivalent in Groovy Script ?
>
> import com.example.auth.principal;
> public String1 abcd(final principal Principal){
> return Principal.getId();
> }

so you are telling me this Java program compiles and runs without error, 
while the same program (just taken as is) in Groovy fails? I mean that 
program there does not look complete of course. But I really wonder 
about Principal.getId() here and principal.getId() in the Groovy 
program. For me it means you are invoking the method getId on the 
instance Principal (frankly, that those classes do not follow the Java 
conventions for class naming makes it quite difficult to understand what 
is what) of the class principal, while in Groovy you call getId() 
directly on the class principal. If getId() is an instance method, then 
this requires an instance of principal for the call.

bye Jochen


Re: Simple question.. how to call a java class method in Groovy Script

Posted by RJ <ss...@gmail.com>.
Thanks for the response, Jochen.  Tried your suggestion, it doesn't like it:

2017-05-22 14:06:15,871 ERROR - <groovy.lang.MissingMethodException: No
signature of method: static com.example.auth.principal.getId() is
applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
wait(long), grep(java.lang.Object)>
org.codehaus.groovy.runtime.InvokerInvocationException:
groovy.lang.MissingMethodException: No signature of method: static
com.example.auth.principal.getId() is applicable for argument types: ()
values: []
Possible solutions: getAt(java.lang.String), wait(), find(), grep(),
wait(long), grep(java.lang.Object)

We try something like this in Java.. Whats the equivalent in Groovy Script ?

import com.example.auth.principal;
public String1 abcd(final principal Principal){
return Principal.getId();
}

On Mon, May 22, 2017 at 2:03 PM, Jochen Theodorou <bl...@gmx.org> wrote:

> On 22.05.2017 19:40, RJ wrote:
>
>> Here is my script. Highlighted the method call.. tried some google
>> searches for the syntax. Thanks for the help!
>>
>> import java.util.*
>> import com.example.auth.user;
>>
>> class EBSAttrRelease {
>>      def Map<UserString, List<UserObject>> run(final UserObject... args) {
>>      def userid=com.example.auth.user.getId()
>>      return [MYLOGINID:userid]
>>      }
>> }
>>
>
> try "import com.example.auth.user as User" instead of "import
> com.example.auth.user" and then "def userid=User.getId()"... assuming of
> course that getId is a static method in the class com.example.auth.user
>
> bye Jochen
>

Re: Simple question.. how to call a java class method in Groovy Script

Posted by Jochen Theodorou <bl...@gmx.org>.
On 22.05.2017 19:40, RJ wrote:
> Here is my script. Highlighted the method call.. tried some google
> searches for the syntax. Thanks for the help!
>
> import java.util.*
> import com.example.auth.user;
>
> class EBSAttrRelease {
>      def Map<UserString, List<UserObject>> run(final UserObject... args) {
>      def userid=com.example.auth.user.getId()
>      return [MYLOGINID:userid]
>      }
> }

try "import com.example.auth.user as User" instead of "import 
com.example.auth.user" and then "def userid=User.getId()"... assuming of 
course that getId is a static method in the class com.example.auth.user

bye Jochen

Re: Simple question.. how to call a java class method in Groovy Script

Posted by Peter McNeil <pe...@mcneils.net>.
Unusual for a Java Class to have a lower case name... just sayin'


On 23/05/17 03:40, RJ wrote:
> Here is my script. Highlighted the method call.. tried some google 
> searches for the syntax. Thanks for the help!
>
> import java.util.*
> import com.example.auth.user;
>
> class EBSAttrRelease {
>     def Map<UserString, List<UserObject>> run(final UserObject... args) {
>     def userid=com.example.auth.user.getId()
>     return [MYLOGINID:userid]
>     }
> }
>
> Error:
> 2017-05-22 13:32:56,986 ERROR - <groovy.lang.MissingMethodException: 
> No signature of method: static com.example.auth.user.getId() is 
> applicable for argument types: () values: []
> Possible solutions: getAt(java.lang.String), wait(), find(), grep(), 
> wait(long), grep(java.lang.Object)>

-- 
web: http://nerderg.com
Twitter: http://twitter.com/pmcneil
Google+: https://plus.google.com/u/0/communities/110661434396927001866