0

In a project I need to replace a Java compilation task with a Scala compilation task. The first step I need to take is to find an equivalent for this: http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html

Is there anything like this in Scala? A brief Google search gave no interesting results.

What I need is a library that allow me to take a file in the form of a list of lines or also a file on the HD and compile it.

I don't simply need to evaluate it but I must be able to get a compiled .class file from it.

yole
  • 92,896
  • 20
  • 260
  • 197
Chobeat
  • 3,445
  • 6
  • 41
  • 59
  • http://stackoverflow.com/questions/20322543/how-to-invoke-the-scala-compiler-programmatically It's about compiling Scala from Scala code, but since it's all in the JVM, this might be translated easily. – mastov Jul 08 '15 at 09:56
  • Is there any example or tutorial in Java? – Chobeat Jul 08 '15 at 09:56

1 Answers1

-1

You can invoke scalac with ProcessBuilder. Otherwise, you'll just need to translate Scala code from the question linked by @mastov, it's pretty trivial:

import scala.collection.JavaConversions;
import scala.tools.nsc.*;

Global g = new Global(new Settings());

Global.Run run = new g.Run();

// assumes you have a Java list of file names
run.compile(JavaConversions.asScalaBuffer(fileNames).toList);
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • I believe there is a typo here and that it should be: `import scala.collection.JavaConversions;` (i.e. minus the "s" on collections). – ZaydH Mar 15 '16 at 11:10