Forum Discussion

ranujn's avatar
ranujn
Contributor
6 years ago

How to call Java main method from Groovy Script in SoapUI

Can someone please advice me how to call java main method along with argument from Groovy script.

 

Below are the steps which I have done

1) Write the code and eclipse under the main method 

2) Taking 4 parameters as input from the main method.

3) Run the class in eclipse and it's working fine.

4) Created the Jar file

5) Place in the bin/ext folder of ReadyAPI

6) Restart ReadyAPI

 

now the question is how can I call the main method from the groovy script. I try creating an object of the class and call method as same we call another method but it's not working. Is there any way to call the main method of the class.

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Did you import the class name where "idea" is package and "Execute" is class name:-

    import com.idea.Execute

    OR 

    import com.idea.* //To import all the classes

     

    Then try this:-

     

    Execute ex = new Execute(); //Add parameters based on requirements.
    ex.call()    //where call() is method of Execute class

    If it solved you problem. Please accept as solution and don't forget to give kudos.

    • ranujn's avatar
      ranujn
      Contributor

      avidCoder, I do not have any method in the class. It's the only main method I have in the class. I try doing this but it did not work

      My java code looks like this

      package project;

      public class MyClass{

      public static void main(String[] args) {
      // performing some functionality here
      }

      }

      Groovy script :

      import project.MyClass;

      MyClass sample = new MyClass();
      sample.main(".abcd","Test","tom","pass"); 

       

      It throws below error and I am not sure, Is this error coming because I am calling main method or any other issue

      ERROR:java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter;

      • avidCoder's avatar
        avidCoder
        Super Contributor

        Ok, Then this Java compatibility issue. What is your soapui version and the Java version?