How I can create a scala application in InteliJ and create a scala clas(Ubuntu) ? - scala

Hi i want to create a first little application with scala in InteliJ. My System is Ubuntu.
I install the Scala Plugin and create a new Project (Scala -> SBT )but if I want add a scala class I dont see this option :(
I think i need the scala sdk but where and how i bind them. Why it doesnt install by the plugin :/

First, if you are going to use SBT, auto-import might be a good idea. Else, you would want to manually import (see SBT tool to the right) to produce a stable, usable project.
Second, you mostly don't need to add java classes on the project folder, which is for the build project itself. You should be seeing a src/main/scala folder there instead. Try refreshing the view (right click menu, synchronize)

Related

Intellij Idea: Scala plugin: No compile library set for module

Wanted to start using intellij idea for my scala project and stumbled upon this link - http://theyougen.blogspot.in/2010/01/how-to-setup-maven-scala-project-with.html
Followed the steps, created a new Scala Project (without sbt), Create a new Scala Class, and copied the HelloWorld code from Scala tutorial - http://www.scala-lang.org/old/node/166.html
Went to Build > Make Project and got following error -
No compiler library set for module.
Went to File > Project Structure. On the left side, clicked on facets, and noticed that Under Compiler Compiler Library was set to none. And there is no other option available in the drop down.
How to solve this?
PS: Googled a lot, could not find any clue on how to fix this.
If on MAC
Download scala from http://www.scala-lang.org/download/
Extract it to some-location/scala
In Intellij Idea go to File, Project Structure and select Global Libraries.
Click on + button
Select Java
Give the path to some-location/scala/lib
Click ok
Apply and OK.
Go to File, Project Structure, facets. You will see a new Scala library in drop-down.

Can't configure Scala in Intellij IDEA 13

I entered Scala courses on Coursera and used to write Scala projects in Eclipse Indigo. All worked well. But now I gonna to convert to my favorite IDE - Intellij IDEA.
But I can't configure it for Scala usage.
What I've already done:
Install Scala, set system SCALA_HOME variable
Install SBT
Install Scala plugin on Intellij IDEA
What a problem:
When I import coursera assignments, Intellij doesn't see some classes like List, Array etc. For example, when I try to import it via Alt+Enter key it propose me java.jang.reflect.Array, java.sql.Array, com.sun.xml....Array. So I can't import Scala Array with tail and head methods.
When I try: New Project -> Scala Module the are to problems:
a) When I choose Set Scala Home it complains that there are missing files
b) When I choose Existent Library there is nothing to choose in Compiler/Standart fields.
Question:
How to configure Intellij properly?
It can be a problem with caches, try File -> Invalidate Caches
Is the directory you specified the right one? It should have bin, doc, etc. in it. If so, try entering the following by hand:
For compiler library, scala-compiler
For standard library, scala-library
IDEA found these for me automatically, but perhaps something went wrong for you.
Make sure to manually add the scala-library as a dependency to your module.
This is not done automatically when adding the Scala facet to an existing module.

Intellij Idea setup for Scala, clarification needed

Using IntelliJIdea 12, i downloaded the Scala plugin and created a HelloWorld application.
The following import seems odd. Why does IDEA not recognize this to be a Scala Application? Is my setup incomplete?
I checked to see where does my compiler points to and got this. Don't really see a way to navigate IDEA to my scala installation.
Please advise.
When creating a new Scala project from the wizard IDEA can download and configure everything for you:
Settings can be changed later in the Scala Facet:
and in Compiler:
Libraries configuration:
Code and imports completion is available from the Scala library:
You need to add Scala as a framework for your project.
To do this, right click on the top level directory in your project, choose "Add Framework Support..." and select Scala. Then Scala will be added as a "Facet" of your project.
Here is a good page with more info:
IDEA Scala Project Configuration Explained
I got around this by downloading the Scala library from scala-lang.org, unzipping it and then pointing the project to it. It worked fine after that. But of course, I'm an eclipse guy so perhaps someone else might be able to give you a better automated (?) solution. Here's what my project looks like in Module Settings -> Libraries:

Scala Compiler not found in Intellij IDEA 11 with Play 2.0 project

I created a project using the typical play new, and then I used play idea to generate the .iml file. When I imported the .iml file into Intellij IDEA, I could not figure out how to get the compiler library to recognize. Below are some screenshots:
Please help!
This is a slight weirdness with the Scala settings in IntelliJ. Currently the only way to register a scala distribution is to create a new project.
Steps:
File > New Project > Create project from scratch
Leave all settings as default. Project name can be anything.
On the "Please select the desired technologies" page, choose Scala. Some GUI elements will appear that allow you to tell IntelliJ how to find your scala compiler and library. Make sure to set the "Level" options to "global".
Click Finish. Close the dummy project that you created, and go back to your real project. The Scala compiler that you registered should now be in the list on your project settings page.
A variation that worked for me: drop the Scala facet and run 'Add framework support...' again.
File / Project Structure / Facets
Click Scala facet then minus to remove Scala facet from your module. Click OK.
Right click your project/module, 'Add Framework Support...', choose Scala.
Enter the path to your Scala compiler and library.
I also ran into this problem, but the workaround as described by Chris B did not work for me, since in my case "Scala" was missing on the "Please select the desired technologies" page.
In my case the problem appeared to be an incompatible Scala plugin. After I reinstalled the Scala plugin it worked fine.

How to run scala code on Intellij Idea 11?

I am new to intellij idea and I decided to shift because I found the scala plugin on eclipse to be annoyingly buggy.
But, intellij idea, which I have heard to be very good, looks difficult to use.
I looked through the getting started with scala plugin page but couldn't find documentation specific to the latest version of lightweight ide of intellij idea 11 for scala.
I have created a project and made a hello world object in scala but I am not able to run it.
On trying to run it, it shows the scala interpreter (type in expressions to get them evaluated).
I don't exactly understand what changes to make in the project structure to be able to run scala code. As of now, i added the jsdk to point to my $JAVA_HOME and the scala library is also added. The scala plugin is also working in that syntax highlighting etc is fine.
The intellij idea user interface is also not very friendly and I don't get how to run the code. What modules am I supposed to add? Also, does compiled scala code run with jvm?
I'll be grateful to anyone who helps out.. I have been putting off writing scala code because I am not able to find THE IDE.
EDIT: Thanks for all the help! I am now able to run a basic scala program. I am trying to add external jars. What is the equivalent of doing Project right click-> Configure Build Path -> adding external jar files in eclipse? I tried adding "dependencies " under modules tab in project structure. It's adding the jar files but somehow the classes in the jar files are not still recognised.
With the Scala plugin installed either
A. Create a new project and select the Scala facet in the creation phase. It will create the Scala library lib and Scala compiler lib and setup the facet for you
B. If you already have a project. Go to Project Structure -> Modules and right click the module and go Add facet and add a Scala facet. Now you need to add scala-library.jar as a library of the module and go into the Scala facet and point it to a library containing scala-compiler.jar
Some more information
this is what your module should look like under project settings
select the Scala facet and this is what you should see (Library name for the compiler is unimportant as long as it says (version xxx) next to the library name
these are the jar files in my scala-compiler lib
and these are the jar files in my scala-library lib
With everything setup like that you should be able to right click -> new Scala class (Select object from the dropdown) in a source directory and add
def main(args:Array[String]) {
println("Hello world")
}
then right click on the class and select Run Classnam.main() and IntelliJ will setup a run configuration for you.
Edit: I can see someone posted somewhat the same I want to say here. I hope this can give a few more in-depths hints, so I will post it anyway :-)
If you would like to run Scala native in IntelliJ (I shifted to IntelliJ and still can't get my hands down) you need to make sure a few things are in order. Most of this happens under File -> Project Structure which requires you to create a project (when you get a hang of it, it is much more logical than Eclipse -- and Netbeans for that matter). I am also assuming you have selected a jdk, but this can also be done in the Project Structure.
Now, to Scala:
Make sure you have the Scala plugin. Visit the Settings (File -> Settings; can also be found at the start-up screen) and locate 'Plugins' (for me it's nr. 8 from the bottom). Under "Browse Repositories" you should be able to search for "scala", find and install a plugin.
1 A. If no plugins pops up you are probably using a version of intellij where scala is not (yet) supported. If that happens you can go to the homepage for the plugin and download the nightly build.
Import Scala as a library in File -> Project Structure -> Global Libraries. Click the plus sign, select Java (Scala is a Java-lib), browse to your scala-dir (which can be downloaded here: http://plugins.intellij.net/plugin/?id=1347) and select the lib directory. Press ok and you should see the library popping up on the list.
Make sure the facet (Scala framework) is in place. Goto File -> Project Structure -> Facets. Click on the plus-sign and find Scala. A sublink should appear (if not double-click the Scala link). Clicking the sublink make sure you have selected a compiler before continuing. This should be provided by the modules selected before. I normally use FSC (Fast Scala Compiler) but it's probably a good idea to test the basic settings before experimenting.
Make sure the Scala Module is in place. In Project Structure -> Modules click on the module you want to compile in scala and click the plus icon above and select Scala. Again be sure to select a compiler library.
If you want to, setup configurations for the compiler under the facet
Use sbt with sbt-idea plugin to generate idea project files for complex projects.
Or
For simple projects.
Add scala nature to the project, and you can right click and run any file extending App.
A good walk-through on how to set up a Scala project in Intellij is located here:
http://sonyarouje.com/2011/03/18/running-scala-in-intellij-idea-10/