I am trying to compile Scala files programmatically using an instance of Global.Run :
val settings = new Settings val reporter = new ConsoleReporter(settings) val compiler = new Global(settings, reporter) val run = new compiler.Run
Unfortunately, I get a MissingRequirementError message:
scala.runtime object not found in compiler mirror
So my question is : how can I compile a file programmatically using the Run class, or what am I doing wrong here?
I tried to find out if I can change the settings to make it work. Actually, I need a list of classes that are in the Scala file in path , not necessarily fully executable output. Therefore, it would be great if the characters remained unresolved (if I could run a subset of the compiler phases).
I am also on the Writing Scala Compiler Plugins , but if I can run it by running the compiler object, I would prefer this solution. I also stumbled upon Is Scala a compiler of a reentrant? (similar code, another question) that makes me think that this might work the way I think.
Edit 1: Added Scala JARs to toolcp (only sample code with absolute path!)
According to the comment, I adapted scalac.bat script class population to my Scala code:
// scalac.bat // if "%_TOOL_CLASSPATH%"=="" ( // for %%f in ("!_SCALA_HOME!\lib\*") do call :add_cpath "%%f" // for /d %%f in ("!_SCALA_HOME!\lib\*") do call :add_cpath "%%f" // ) new File("C:\\Program Files\\scala\\lib").listFiles.foreach(f => { settings.classpath.append(f.getAbsolutePath) settings.toolcp.append(f.getAbsolutePath) })
source share