title: Load java class in scala at runtime
body: <p>I have a JAR file with java classes, which I want to use in my scala application. I don't want to add the JAR to the <em>lib/</em> folder because I do not want to rebuild my scala application every time the JAR is changed. </p>
  
  <p>So I tried my hands with scala reflections and class loaders and I was able to load the class, but I don't know how to use the methods of the class further in my scala application.</p>
  
  <p>Here is my attempt so far,</p>
  
  <pre><code>scala&gt; var classLoader = new java.net.URLClassLoader(Array(new File("java-module.jar").toURI.toURL),this.getClass.getClassLoader)
  classLoader: java.net.URLClassLoader = java.net.URLClassLoader@130b3958
  
  scala&gt; var javaClass = classLoader.loadClass("com.sample.myClass")
  javaClass: Class[_] = class com.sample.myClass
  
  scala&gt; javaClass.getMethods.foreach(println)
  public java.lang.String com.sample.myClass.myMethod(java.lang.String)
  public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
  public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
  public final void java.lang.Object.wait() throws java.lang.InterruptedException
  public boolean java.lang.Object.equals(java.lang.Object)
  public java.lang.String java.lang.Object.toString()
  public native int java.lang.Object.hashCode()
  public final native java.lang.Class java.lang.Object.getClass()
  public final native void java.lang.Object.notify()
  public final native void java.lang.Object.notifyAll()
  </code></pre>
  
  <p>I want to use the method <em>myMethod</em> from the newly loaded class. </p>
  
  <p>How can I go further to create an object of this particular class and use it's methods?</p>
  
  <p><strong>Edit:</strong> Added output for each line of code executed</p>