Forum Discussion

roryLIT's avatar
roryLIT
Contributor
11 years ago

Access jar file java classes using Groovy

I've created a jar file containing a number of java classes that I want to reference and use in a groovy script step. What all do I need to put in the groovyscript to access the classes and get the information I need? I have saved the jar file to the bin/ext folder and restarted soapUI

Thanks

7 Replies

  • Tried that but no success getting an 'unable to resolve class' error. Here is the code I have. Any thoughts?

    def folder = new File( "ext/ALMIntegration.jar" )

    if( folder.exists() )
    {
    ALMConnectionManager newConnection = new ALMConnectionManager()
    host = newConnection.getHost();
    log.info host
    }
  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    hi, if you did not add import clauses in the groovy script, you should used fully qualified class names
    For instance

    my.package.ALMConnectionManager newConnection = new my.package.ALMConnectionManager()


    does it help?
  • Yep that did the trick! Had to put in the package name before the class. Thanks!
  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    hi, good news
    could you try again to put the jar only in the ext lib? I would be interesting to have a good understanding of how to manage external classes in groovy scripts

    Thanks in advance
  • Yea it's in the bin/ext folder and works fine! Is that what you mean?
  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    yes, that's was what i had in mind (I've just realized that my question contained typos, sorry about this).
    thanks for the feedback