Access the Eclipse Scala compiler from the terminal - eclipse

I'm just starting out with Scala (trying to setup Eclipse, Lift and SBT on Mac Lion) and I'm not sure if I need the scala compiler through homebrew or can I just use the built in Eclipse Scala compiler through Eclipse and (if I also need to) through the Terminal.
If that's a good idea, how do I run it through the terminal ?

You won't be able to access the Eclipse-IDE scala compiler through terminal, so if you want terminal access, you should install a standalone scala interpreter separately.
While you don't technically need terminal access since Eclipse will compile everything for you and you can run the interpreter through Eclipse (Window -> Show View -> Scala Interpreter), I like to have the option, so I always have a separate installation of the same version of the compiler that Eclipse uses.

Instead if installing scala, I normally have a blank sbt project, and start the scala REPL by doing
sbt console
This allows me to easily change scala versions and if I add dependencies to the project, they will be added to the console classpath.

Related

How to use existing Scala with Intellij

I already have brew install scala - I am able to run Scala via command line. After that I installed IntelliJ version 2016.1.3
While installation process of IntelliJ, I was asked to install Scala plugin but i clicked no - because I already have Scala installed
Now I am trying to figure out where exactly we can create a Scala application with the use of my existing Scala installed. How and where in the IntelliJ can I set this up? I can only see Java projects available to be created.
Thanks
You can't. The Scala you have installed is a completely different thing from the IDEA Scala plugin.
The Scala plugin is what you need to handle Scala projects, editing Scala files, etc. in IDEA. The command-line Scala is just the compiler and the standard library, it doesn't know anything about IDEA.
Also, for the command line you should install SBT instead of working directly with the Scala compiler unless you want to handle dependencies, classpaths, etc. manually (you don't).
If you want to create Scala application using IntelliJ IDEA, you will need to install the Scala Plugin.
Step 1: Open IntelliJ Preferences or Settings
On Mac:
Open IntelliJ IDEA.
Then click on the menu item IntelliJ IDEA and select Preferences.
On Windows:
Open IntelliJ IDEA.
On the bottom right corner of the Welcome to IntelliJ screen, select Configure.
Step 2: Find and install Scala Plugin
After opening the Preferences or Settings screen from Step 1, click on the Plugins section on the left panel.
Then click on the Install JetBrains plugin… button.
This opens another window which has a Search box on the top left corner. Type in Scala in the search box and this will list the Scala plugin which you need to install.
Hit the Install button to kick off the installation.
Do not forget to Restart IntelliJ following the install.
And Voila! You should now be able to create Scala projects in IntelliJ.
For further instructions on how to install Scala plugin in IntelliJ, you can follow the instructions from www.allaboutscala.com

Call Bundled SBT's Commands in IntelliJ Scala Plugin

I am trying to call gen-android command after installing android-sdk-plugin to the project. However, I can't find out how to call a command of the bundled SBT, or do it outside of IDE.
How do you call commands of a bundled SBT of Scala plugin (v.2.2.0) in IntelliJ (v.15.0.3)? Or, is it possible to use the SBT executable outside IntelliJ?
I can of course use a normal SBT regardless but am just curious if I can do everything using one different SBT inside IDE (because it'd be convenient!)

Scala build process

First some context:
My aim is to use scala alongside a testing environment, preferably in an ide.
At first I installed scala (v. 2.10.1) and sbt and it worked. I used emacs and a shell.
Then I wanted to use eclipse and installed the sbt plugin. But when I tried the FlatSpec example of the scalatest website together with the scalatest lib, it did compile but 0/0 tests did run.
In intellij I tried the same example but although I gave my sdk location, the collection package wasn't found.
My problem:
I don't understand what I have to tell my ide or what I have to write (maybe files for maven or make etc.) or where I can learn all that.
My question:
What has the ide to know if I want to run a scala project?
- location of sdk, jdk, sbt, my_project, ...
- versions of scala, java etc.
What else must it know?
IntelliJ has build in support for sbt projects. My work flow is the following :
Create a project (in the shell) using sbt. Basically you have to create a build.sbt and the necessary directory structure
`src/main/scala`
`src/main/resources`
`src/test/`
The in IntelliJ just do Open -> select build.sbt.
Also check auto-import checkbox.
Everything should work after this.
NOTE: You may have to install the Scala and sbt plugin for the above to work.

IntelliJ 404 scala lang

Ok, I need some help in setting up a Scala project with IntelliJ, I have download and installed the project successfully, but i have had issues when it comes to installing the Scala compiler itself, WHen i go to configure a new Scalaa project and choose to set the Scala home, I choose the download Scala option and i get the following error "downloading failed, connection failed with error 404: http://www.scala.lang.org/downloads.distrib/files/scala2.10.0+RC2.tgz" i have tried downloading the things, such as primefaces and jSF through intelij, and they all work fine, any suggestions?
Download Scala manually and just select proper directory in new project window.
http://www.scala-lang.org/download/
You should be using SBT to define and build your project. Among other things, it handles retrieving the Scala compiler and libraries. IDEA is similarly self-contained as far as its Scala plug-in's internal Scala compiler is concerned. By using SBT and IDEA (see below for connecting the two), the only thing not covered is a Scala REPL for use outside of either SBT or IDEA. If you're using a Mac, Homebrew includes a Scala formula. Because SBT retrieves the Scala compiler and libraries for the version of Scala you specified, everything is self-contained.
By far the best way to build and maintain IDEA project definitions for Scala projects is with the sbt-idea plug-in for SBT. Once you install that plug-in, which is trivial, you simply use the gen-idea SBT task it provides. When your dependencies change, you run gen-idea again to update the project.

Should I install Scala separately for command line and Eclipse IDE?

I've installed Scala IDE for Eclipse using the update mechanism, and then I found that there's no command line tools included there. So is it correct that I should download another copy of Scala package for the command line support and maintain both separately?
Or is there an integrated way to get it work in both environments? I just want to write and debug code in Eclipse and occasionally run it on the command line.
First, you can open a Scala command-line within Eclipse. Just go to Window -> Show View -> Scala Interpreter, and it will open an interpreter window that has your project loaded into the classpath.
Second, there's nothing wrong with having a separate Scala installation for command-line use. I do this. It's often convenient to have a few terminal windows where you can run stuff or quickly test bits of code.
You need to install the scala compiler first. Otherwise you can not use the eclipse plugin. If you have installed the scala compiler, you just need to add it to your classpath. Now you can type scala into any terminal you are using and the REPL starts.