Created
March 18, 2012 11:15
-
-
Save BowlingX/2070600 to your computer and use it in GitHub Desktop.
SBT Reflective load a Class on fullClasspath
This file contains 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
/* 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