Skip to content

Instantly share code, notes, and snippets.

@BowlingX
Created March 18, 2012 11:15
Show Gist options
  • Save BowlingX/2070600 to your computer and use it in GitHub Desktop.
Save BowlingX/2070600 to your computer and use it in GitHub Desktop.
SBT Reflective load a Class on fullClasspath
/* File: Build.scala in ~/project */
/*...Build Definition...*/
/* This Task should load a Class on my Project*/
val taskKey = TaskKey[Unit]("task-name", "task-description")
val myTask = taskKey <<= (fullClasspath in Runtime, scalaInstance) map { (cp, si) =>
val loader = ClasspathUtilities.makeLoader(cp.files, si)
// Load class with Reflection
val cls = loader.loadClass("com.myCompany.myClass")
// Call Method
cls.newInstance().asInstanceOf[{
def myMethodToCall(param1:String, param2:String)
}].myMethodToCall("one", "two")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment