Last active
August 29, 2015 14:20
-
-
Save wfaler/498e61d0f4879b983434 to your computer and use it in GitHub Desktop.
compile scala dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.tools.nsc._ | |
import java.io._ | |
val scalaLibraryPath = "/Users/wfaler/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.2.jar" | |
val s = new Settings() | |
s.bootclasspath.append(scalaLibraryPath) | |
s.classpath.append(scalaLibraryPath) | |
val g = new Global(s) | |
val run = new g.Run | |
run.compile(List("test.scala")) // invoke compiler. it creates Test.class. | |
val classLoader = new java.net.URLClassLoader( | |
Array(new File(".").toURI.toURL), // Using current directory. | |
this.getClass.getClassLoader) | |
val clazz = classLoader.loadClass("Test") // load class | |
clazz.newInstance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment