If I've writen a Scala program, can I compile it in a way so that anybody with a standard Sun Java JVM can run it? I guess the Scala compiler would have to include the Scala-specific API code in the compiled project? The reason I'm interested is that our class projects can usually be delivered in whatever language one prefers, but TAs grading the deliveries usually want to run the code either on their own machine or on lab machines.
You do not need to do anything special to run your compiled Scala program on JVM. It is just plain JVM bytecode. Only thing you need is to make sure that standard Scala library (scala-library.jar) is included in your class path at runtime. This is only extra dependency (or perhaps you also may need scala-swing.jar if you use Swing wrappers for your GUI).
If you worry about convenience for the user you may even package your application to single jar so it contains contents of scala-library.jar and your own classes and resources. But personally I'd do that only if this jar is executable (can be run as java -jar yourApplication.jar).
Notes about Scala library :
Yes. If you include the appropriate scala library jar file in the classpath, a scala program can be run using java, since compiled scala code is the same as compiled java code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With