3

I have the following Scala class, I am able to run it from command line by first typing sbt then in sbt mode. But I am not able to run it from eclipse . I am already in scala perspective.

> run-main bcomposes.twitter.QuerySearch #IPL


package bcomposes.twitter

import twitter4j._
import collection.JavaConversions._

/**
 * Gets a Twitter instance set up and ready to use.
 */
trait TwitterInstance {
  val twitter = new TwitterFactory().getInstance
}

/**
 * Given a command line query, search for tweets and print
 * them.
 */
object QuerySearch extends TwitterInstance {

  def main(args: Array[String]) { 
    val statuses = twitter.search(new Query(args(0))).getTweets
    statuses.foreach(status => println(status.getText + "\n"))
  }

}
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Shakti
  • 2,013
  • 8
  • 27
  • 40
  • 1
    "I am not able to run it from eclipse" - Why not? Did you try? What happened? Did you get error messages? – Jesper Apr 12 '13 at 14:50
  • 1
    Right-click in the editor that contains your Scala source code with the `main` method, choose Run As / Scala Application. – Jesper Apr 12 '13 at 14:52
  • When I do a right click , I see Run As -> Run Configuration and not Run As Scala Application – Shakti Apr 12 '13 at 15:20
  • may be you didn't write the main method or extends App: `object Hello extends App{}` (or) `def main(args : Array[String])` – sudha Dec 17 '16 at 11:29

5 Answers5

6

Make sure the package name you specified under which your scala object file is added matches the package name you mentioned in your code. So, correct this and then check, "Run as Scala Application" should be available now

1

Your Scala file has to be a part of Scala project. Create Scala project using Scala Project wizard, add your file to it and try again.

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
0

Try to click right button on the Scala object with main method (not on the root project element). Then the "Run as... Scala application" menu item appears.

tse
  • 5,769
  • 6
  • 38
  • 58
0

"Run as Scala application" will show in Eclipse Scala IDE only if we extends the Scala object with 'APP' class.

Example:

package grreter
object Exp extends App{
  println("Hello, New World!")
}

(Note: if you comment "extends App" then 'Run As Scala Application' will not show.)

-1

The way I solve this problem is using maven to compile and package the project , when the maven build is correct, the "run as scala application" appear again.

Hatter Bush
  • 215
  • 1
  • 3
  • 15