0

I have this code that works perfectly when used in the scala REPL, but when I try to compile it using scalac, I get a bunch of errors.

This is my code (too long to post here) - http://pastebin.com/rkKL3xjH

And the errors I get are:

 error: expected class or object definition

How do I compile my code so that it can be opened on another computer and executed? I am new to scala and programming so I don't know how to do this yet or what needs to be included in my file.

Thank you

Chris
  • 233
  • 2
  • 5
  • 14
  • possible duplicate of [How do I create executable Java program?](http://stackoverflow.com/questions/804466/how-do-i-create-executable-java-program) – om-nom-nom Apr 03 '13 at 15:43
  • As for your code: you wont get those errors if you place your code into a [proper top-level object](http://stackoverflow.com/questions/11667630/difference-between-using-app-trait-and-main-method-in-scala) – om-nom-nom Apr 03 '13 at 15:44
  • 1. what do you mean by "works when used in scala" 2. making an executable jar comes after producing compilable code. 3. an executable jar is different from something that can be executed on any computer. Please sort out what you really want to know and edit the question accordingly. – Jens Schauder Apr 03 '13 at 15:45
  • Sorry if I confused you - I changed by question, but basically I want my file to run on another computer that does not have scala installed , just like any other program. – Chris Apr 03 '13 at 15:50

1 Answers1

1

You can use the SBT plugin for assembly to do what you want.

Follow the instructions here: https://github.com/sbt/sbt-assembly.

By default the fat jar that it produces will have all of the class files that you need to run the jar on a computer that just has java installed.

Of course this is all predicated on the fact that you create a SBT project and use SBT as a build tool.

In order to use SBT as a build tool you can follow the instructions located here:

https://github.com/sbt/sbt

Edit:

In addition to using sbt you'll have to form up your application in a standard way that has a "main" function to execute.

object HelloWorld {
  def main(args: Array[String]) {
      //Execute code here
  }
}

Though it would be hideous, you could probably just paste your entire program into the main and it might work.

coltfred
  • 1,470
  • 9
  • 17