0

I have the following code to compile scala code at runtime in a Java program

    Settings s = new Settings();
    Global g = new Global(s);
    Global.Run run = g.new Run();
    List<String> files = new LinkedList<>();

    files.add("src/main/java/scala/rules/ScalaRuleBasedStrategy.scala");

    run.compile(JavaConverters.asScalaBufferConverter(files)
     .asScala().toList());

But I am getting this error:

Exception in thread "main" java.lang.NoSuchMethodError: scala.tools.nsc.Global$gen$.mkBlock(Lscala/collection/immutable/List;)Lscala/reflect/internal/Trees$Tree; at scala.tools.nsc.ast.parser.TreeBuilder.makeBlock(TreeBuilder.scala:110) at scala.tools.nsc.ast.parser.Parsers$Parser.block(Parsers.scala:1689)

1 Answer 1

1

Try

Settings s = new Settings();
MutableSettings.BooleanSetting usejavacp = s.usejavacp(); // added
usejavacp.value_$eq(true); // added
Global g = new Global(s);
Global.Run run = g.new Run();
List<String> files = new LinkedList<>();

files.add("src/main/java/scala/rules/ScalaRuleBasedStrategy.scala");

run.compile(
  JavaConverters.asScalaBufferConverter(files)
    .asScala().toList()
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.