So im trying to test two java programs and if they have the same output, and I want to do this within scala. So how would i do this within scala, should i use the java runtime library or is there one in scala?
-
Can you clarify? You want to write unit tests for java code in scala? scalatest.org for example advertises that "you can test either Scala or Java code."zapl– zapl2015-12-06 15:29:17 +00:00Commented Dec 6, 2015 at 15:29
-
@zapl what i want to do is, i have two .java files which i want to compile and execute from within my scala code, and check whether the outputs are the same. I know you can run a java program from another java program by using the runtime library to do terminal commands like javac etc, but im not sure if scala has one similar to that? if that all made sense?Alan Liang– Alan Liang2015-12-06 16:40:07 +00:00Commented Dec 6, 2015 at 16:40
-
1Scala runs in JVM and therefore and can use any of the java libraries. But I really don't see any reason to compile your java programs from Scala.pedrofurla– pedrofurla2015-12-06 16:48:28 +00:00Commented Dec 6, 2015 at 16:48
-
1If you really want you can start with the compilation process from scala. Scala has it's own runtime version stackoverflow.com/questions/16162483/execute-external-command and you can access java's runtime as well daily-scala.blogspot.de/2009/08/calling-java-apis.htmlzapl– zapl2015-12-06 17:13:09 +00:00Commented Dec 6, 2015 at 17:13
-
@zapl This should be an answer.Alexey Romanov– Alexey Romanov2015-12-06 18:22:55 +00:00Commented Dec 6, 2015 at 18:22
Add a comment
|
1 Answer
You can use the JavaCompiler API. Or, simpler, just run javac in an external process, as @zapl's comment says.