Reputation: 2033
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"))
}
}
Upvotes: 3
Views: 10672
Reputation: 61
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
Upvotes: 6
Reputation: 315
"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.)
Upvotes: 0
Reputation: 225
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.
Upvotes: -1
Reputation: 6069
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.
Upvotes: 0
Reputation: 17359
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.
Upvotes: 1