Forum Discussion

PeterT's avatar
PeterT
Occasional Contributor
17 years ago

Using user-defined java (or groovy) class in script

Hi there

So, I'm finally getting a bit of a handle on SoapUI and Groovy.  One thing (at the moment) that I'm having trouble with is using a user-defined java class in my Groovy Script. 

I've made a very basic class, Test.java, which just returns a string. I've compiled it and put both the .java and .class file in the \soapUI-2.0.2\bin\ext folder and imported the package in my script.  When I try to run the script however it cannot resolve the new object that I created (e.g. def t = new Test()). 

I know that this should be doable and I'm sure I just haven't put the .class file in the right location or something like that.

Can anyone shed any light on this?

Cheers

Peter

5 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Peter,

    you need to package your class file in a jar archive and then put that .jar file in the bin\ext folder.

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • PeterT's avatar
    PeterT
    Occasional Contributor
    Hi Ole

    Actually I did that and while I could see in the command window that it was picking up the .jar file it still didn't recognise the object I was trying to create. Perhaps I screwed up creating my .jar, will give it another go.

    Thanks for your help again.

    Cheers

    Peter
  • omatzura's avatar
    omatzura
    Super Contributor
    Ok, hope it works better this time, let me know if we can help some more!

    regards!

    /Ole
    eviware.com
  • Pesotska's avatar
    Pesotska
    New Contributor
    Hi,

    I have also the problem  with user-defined java class in Groovy script

    I've made a very basic class Test.java, which returns a string.
    I have packaged Test.class in a jar archive and then put test.jar file in the soapUI-2.0.2\bin\ext folder.

    Groovy script:

    import soapuitest.*

    def test = new soapuitest.Test()[/font:1zzjuces]


    By script Running:

    org.codehaus.groovy.control.MultipleCompilationErrorsException:
    startup failed, Script14.groovy: 3: unable to resolve class mysoapuitest.GenerateExternalBookingId @ line 3, column 14.
    org.codehaus.groovy.syntax.SyntaxException: unable to resolve class mysoapuitest.GenerateExternalBookingId @ line 3,
    column 14. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:113)
    at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:132)
    ....

    Could someone help me?

    Best regards,
    Liliya
  • Pesotska's avatar
    Pesotska
    New Contributor
    Sorry!

    It functions nevertheless, error lay in the JAR!

    Best regards,
    Liliya