Skip to content

Instantly share code, notes, and snippets.

@gregturn
Created August 24, 2011 17:55
Show Gist options
  • Save gregturn/1168692 to your computer and use it in GitHub Desktop.
Save gregturn/1168692 to your computer and use it in GitHub Desktop.
Embedding scala compiler in java
try {
Settings settings = new Settings();
settings.usejavacp().tryToSetFromPropertyValue("true");
settings.stopAfter().tryToSetColon(Nil.$colon$colon("dce")); // same as "dce" :: Nil in scala
settings.debug().tryToSetFromPropertyValue("true");
System.out.println("About to compile " + new String(sourceUnit.getContents()));
PrintWriter out = new PrintWriter("output.txt");
IMain main = new IMain(settings, out);
boolean success = main.compileString(new String(sourceUnit.getContents()));
System.out.println("Compiled? " + success);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment