Search code examples
javascalajava-compiler-apiscala-compiler

How to compile and run scala code at runtime from a java program?


I already have a program that uses JavaCompiler api for compiling Java code at runtime. Can I use the same compiler for scala code? If not, what is the best way to compile scala code in a Java program?

Thanks


Solution

  • See the following answer, and in it, also the answer linked by @mastov. You may, however, be able to use the new process handling capabilities in Java 9 instead of ProcessBuilder.

    Compile Scala code to .class file, in Java

    On Java 9 Process API:

    https://www.javaworld.com/article/3176874/java-language/java-9s-other-new-enhancements-part-3.html