It seemed easier to not have you close and relocate projects, which would have taken more explanation. Fortunately, sbt can create the proper manifest file that tells java (called from the scala command) where your main is. I tried various workarounds (like creating a java file with a java mail that called the Scala main) but nothing worked. The order I described things may seem a little strange: why did I have you cat the helloWorld program instead of using Eclipse to type it in? Of course, I had already downloaded Eclipse and created my project entirely in Eclipse and figured out the Run/Debug settings, but simply could not get it to work outside of Eclipse. The name of the jar file is obviously built from the build.sbt command’s keywords, and you can see how easy it would be to have a build.sbt that has a different version of helloWorld or of Scala that would create an output file of a different name so you could maintain separate versions. Scala target/scala-2.10/helloWorld_2.10-1.0.jarĪt the command line should also print “Hello world!”. If you’re in the helloWorld directory, typing: Give it the name sbt packageBin and save it:īy selecting that tool, you’ll create an executable in target/scala-2.10/helloWorld_2.10-1.0.jar that can be run with the scala command (which sets up paths properly for you). If you want to create a jar file that can be run independently of Eclipse, go to Run > External Tools > External Tool Configurations and in the Main tab, under Location fill in where you put the sbt script file (in my case, /usr/local/bin/sbt), under Working Directory enter $, and under argument enter packageBin. With a more complicated Scala main that accepts command line arguments, you can add those into the Run/Debug setting, too. You should see “Hello world!” in Eclipse’s Console. Select OK and then when you run, use that launch configuration. Eclipse can’t understand the Scala main signature, so you can’t select HelloWorld from the pop-up, you have to type it by hand. setting, and in the main tab put HelloWorld as the Main class. If you want to run the hello world from Eclipse, right-click on the project and choose Properties, choose Run/Debug Settings, create a New. and choose General > Existing Projects Into Workspace and navigate to the helloWorld directory and choose that. Now, you’re ready to fire up Eclipse, and then Import. (The Eclipse IDE version also comes with the Scala Worksheet plugin, which is pretty amazing in itself.) If you already have Eclipse installed, you can get the Eclipse Scala plugin and install it. The easiest way to do this is to get the Scala IDE, which is Eclipse Indigo (two releases back, but the previous release was not well-received, and the latest release, Kepler, just came out this summer). jar files to implement the eclipse command, then invokes the eclipse command which makes a project directory suitable for Eclipse to open.įourth, install Eclipse. I installed it into /usr/local/scala and edited ~/.profile to add /usr/local/scala/bin to the end of PATH and to create SCALA_HOME=/usr/local/scala. I put all of the executables for Scala, sbt, etc, in /usr/local.įirst, install Scala, which currently is up to 2.10.2: go to and press the “Download” button. I created a /usr/local directory years ago and am not sure if it exists on a stock Mac system. I assume you are comfortable with the Mac/UNIX command line, since you’re going to be programming. Unfortunately, the second problem remains, so I’m writing this posting to document how I got Scala working on a Mac, with Eclipse and SBT (Simple Build Tool) in a way that everything works from Eclipse and also that I can generate JAR files that work as well. Scala totally eliminates the first problem: it’s Java done right. Over the years, two things have kept me from adopting Java: 1) Java makes you do too much work and has too many seams - the seams hurt my head - and 2) the Java tool chain is fussy and hard to get right. Clojure is tempting - I love Lisp - but ultimately, Scala won out. I wanted to adopt a language that runs on the JVM (Java, Scala, Clojure, Groovie, et al) that’s fun to use, but deep. I still really like R and use it every day, but it’s not a great choice for a general-purpose programming language. Scala is now the official general-purpose programming language of thinkinator.
0 Comments
Leave a Reply. |