title: load external jar in groovy script in SoapUI
body: <p>I need to call a method inside Jar from groovy script inside SoapUI project.</p>
  <p>Due to the lack of administrative access I can't place that jar in &quot;../bin/ext&quot; folder in SaopUI intall directory.</p>
  <p>So the only option left is load the jar in runtime and call the method. Very simple approach.</p>
  <p>I tried the below approach.</p>
  <pre><code>this.class.classLoader.rootLoader.addURL(new URL(&quot;file:///H://Foo-2//Foo.jar&quot;));
  def cls = Class.forName(&quot;test&quot;).newInstance();
  cls.add()
  </code></pre>
  <p>This is not working as rootLoader is <strong>null.</strong></p>
  <p><code>second approach .</code></p>
  <pre><code>def classLoader = ClassLoader.systemClassLoader
  def newClassLoader = new URLClassLoader([new File(&quot;file:///H://Foo-2//Foo.jar&quot;)
          .toString().toURL()] as URL[], classLoader)
  def cls = Class.forName(&quot;test&quot;).newInstance();
  </code></pre>
  <p>this is not working too , it's giving me <strong>ClassNotFoundException</strong>.</p>
  <p>I spent a day in this. even change the class name to lower case after seeing this <a href="http://www.groovy-lang.org/mailing-lists.html#nabble-td372450" rel="nofollow noreferrer">thread</a>.</p>
  <h1>Edit 1</h1>
  <p>I tried this <a href="https://community.smartbear.com/t5/SoapUI-Open-Source/Soapui-is-not-loading-external-jar-file-location-added-to/td-p/7619" rel="nofollow noreferrer">too</a>. and change my code like this.</p>
  <pre><code>def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
  def classpathHacker = new com.eviware.soapui.support.ClasspathHacker ()
  log.info &quot;utils=&quot; + groovyUtils
  mystring = &quot;file://H://Baz.jar&quot; 
  com.eviware.soapui.support.ClasspathHacker.addURL( new URL(mystring) )
  def cls = new bar() // how to call the static method add of `bar` class ?
  log.info cls
  </code></pre>
  <p>My Jar code is too simple. Here it is</p>
  <pre><code>public class bar {
      public static void main(String[] args) {
          add();
          }
          public static void add(){
              String path = &quot;H:&quot; + File.separator + &quot;Groovy&quot; + File.separator + &quot;hi.txt&quot;;
              File f = new File(path);
  
              f.getParentFile().mkdirs(); 
              try {
                  f.createNewFile();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  }
  </code></pre>
  <p>What all the other option I have? What i am doing wrong?</p>
  <h1>Solved. Here is the final Groovy script.</h1>
  <pre><code>def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
  def classpathHacker = new com.eviware.soapui.support.ClasspathHacker ()
  
  path = groovyUtils.getProjectPath()
  myfile = new java.io.File(path + &quot;/Baz.jar&quot;)
  mystring = &quot;file://&quot; + path + &quot;/Baz.jar&quot;
  log.info &quot;myfile=&quot; + myfile
  
  classpathHacker.addFile( myfile )
  com.eviware.soapui.support.ClasspathHacker.addFile( myfile )
  com.eviware.soapui.support.ClasspathHacker.addURL( new URL(mystring) )
  //import Baz
  
  def instance = this.class.classLoader.loadClass( 'bar', true, false )?.newInstance()
  instance.add();
  </code></pre>