Forum Discussion

tom_13's avatar
tom_13
Contributor
16 years ago

Re: call java method from groovy

Hi,
I’m using free soupUI. I need to call java method from jar file. I have added this jar file to soupUI classpath, but when I write
 import myfile.jar
and then try to call class with methods from jar, I got error:
 unable to resolve class myfile.jar

What I’m doing wrong?
  • Hi,

      as I know, you should put your JAR file to  soapUI / bin / ext      directory, then restart soapUI. Must restart

      Good luck.
  • corki wrote:

    Hi,

      as I know, you should put your JAR file to  soapUI / bin / ext       directory, then restart soapUI. Must restart

       Good luck.


    Yes I did it. But after import I have an error.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    It looks like you're going about importing your classes in the wrong way. After adding the jar file, you can import the package with your classes. For instance, to use a class com.example.MyClass, you include it in your jar and add the jar to the classpath, then you would use (for instance):


    import com.example.MyClass;
    MyClass myClass = new MyClass():


    Hope this helps!

    Regards,
    Dain
    eviware support
  • Hello,
    I have done like you said.

    I have jar fail jeveragwutils.jar, which I put into eviware\soapUI-2.5.1\bin\ext. Then restart soapUI.
    After that i wrote:
    import  com.jeveragwutils.GWInvoker


    import  com.GWInvoker


    import  GWInvoker



    For all tree variants i got one error:

    unable to resolve class
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Tom,


    The procedure suggested by corki is the correct one.

    After copying your JAR file(s) to $SOAPUI_HOME/bin/ext folder and restarting soapUI the public classes from the corresponding JAR file(s) should be visible to Groovy run-time after you import the corresponding symbols, i.e. Java types.

    In Groovy, you can either import a Java type by either using FQN (i.e. fully-qualified name comprised out of package name and class name) or by using wild card notation (which allows you to import all types from a single package, excluding eventually sub packages).

    Since I cannot find online the JAR you're referencing I cannot tell you what is the correct way to import GWTInvoker type. I suggest using JAR to find out what is the proper package name:

    jar -tvf jeveragwutils.jar

    Then you should get the proper package name by removing slashes with dots.

    Cheers!
    /Nenad Nikolic a.k.a. Shonzilla