0

I am new to the scala language. I already downloaded the Scala 2.11.6 binaries for windows and also Scala Eclipse IDE.

This is my first Program.

class main { def main(args: Array[String]){ val pt = "String"; print(HelloFunction(pt)); } def HelloFunction(value: String) : String = { return "Hello "+value; } } 

I can't run this program with Eclipse. The IDE asks for run configurations. What are the correct configurations for Scala with Eclipse?

2 Answers 2

1

It would be esiest to install the latest version of the Scala IDE for Eclipse from http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site which URL is given on http://scala-ide.org/download/current.html. It requires Eclipse Luna so that should be installed first.

To set that up in Eclipse, go to Help/Install New Software. In the Available Software window that comes up click on the dropdown menu button at the top and check if the site for the Scala IDE download is already there. If it is there then select it so it shows up in the Available Software Name column. From there select the components you want and then click on the Next button at the bottom for two screens, accept the license agreement on the 3rd screen and click on Finish to begin the installation.

If you did not see the the download link in Available Software then it can be added by clicking on the Add button on the right near the top to get the Add Repository popup and in that enter the download URL in the Location field and a name in the Name field. The name is to help recognize the URL in the future. Then click Ok and now you can select the URL from the dropdown as and do the installation as described above.

PS: The Scala IDE in Eclipse requires a runnable program to be in an object with a main method within a package. To do that after creating a package in a project, in that package create a scala object by selecting File/New/Scala object and giving it a name. Then an edit window for the object will come up. In the edit window add "extends App" after the object's name or code a main method in it to make it runnable. In that same file a companion class and other objects can be created outside the main object. Here is an example for demonstrating communication between an object and its companion class:

// all in file HelloWorld.scala object HelloWorld extends App { var o = "from object" def funp = println("Hello, world!") funp val A = new HelloWorld() A.helloClassFun println(A.h) A.funq } class HelloWorld { def helloClassFun = println("hello class") var h = "from class" val p = HelloWorld.o def funq = HelloWorld.funp } 
Sign up to request clarification or add additional context in comments.

Comments

1

It's not an Scala-IDE, but a scala issue. You have to use an "object" instead of a "class".

object main { def main(args: Array[String]){ val pt = "String"; print(HelloFunction(pt)); } def HelloFunction(value: String) : String = { return "Hello "+value; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.