Published on Feb 18,2016
6.7K Views
Email Post

This blog post will help you understand how to install and set up sbteclipse plugin for running Scala application in Eclipse IDE. First, let’s understand what is SBT. Wikipedia defines it as the “the de facto build tool for the Scala community, used by the Lift web framework and Play Framework.” It is essentially an an open source build tool for Scala and Java projects, similar to Java’s Maven or Ant.

Its main features are:
• Native support for compiling Scala code and integrating with many Scala test frameworks
• Build descriptions written in Scala using a DSL
• Dependency management using Ivy (which supports Maven-format repositories)
• Continuous compilation, testing, and deployment
• Integration with the Scala interpreter for rapid iteration and debugging
• Support for mixed Java/Scala projects

Sbteclipse however, is a plugin for sbt 0.13. In order to setup this plugin, one should have sbt installed first on their system.
Let us download sbt first.

Command: wget http://dl.bintray.com/sbt/rpm/sbt-0.13.8.rpm

command1-running-scala-application-in-eclipse

command2-running-scala-application-in-eclipse

Command:  sudo yum localinstall sbt-0.13.8.rpm

command3-running-scala-application-in-eclipse

command4-running-scala-application-in-eclipse

Command: wget http://dl.bintray.com/sbt/rpm/sbt-0.13.8.rpm

Now let’s check the sbt version.
Command: sbt –version

5-running-scala-application-in-eclipse

To import your project to Eclipse, you must add sbteclipse to your plugin definition file. You can use either the global one at ~/.sbt/plugins/plugins.sbt or the project-specific one at PROJECT_DIR/project/plugins.sbt:

Let’s add the plugin globally so that we need not add it in each project individually. The steps for this are:
Make a plugin directory inside .sbt/0.13/
Command: mkdir -p .sbt/0.13/plugins
Create a file plugins.sbt
Command: sudo gedit .sbt/0.13/plugins/plugins.sbt

6-running-scala-application-in-eclipse

In order to add the sbteclipse plugin, just add this setting to this file.

addSbtPlugin(“com.typesafe.sbteclipse” % “sbteclipse-plugin” % “4.0.0”)

7-running-scala-application-in-eclipse

Now the sbteclipse plugin is set.
Once the installation is complete, we will be able to use the additional command eclipse when we launch sbt.
These are the steps to run a project directly by sbt. We will next learn how to run the project in eclipse.
sbt package

mkdir helloworld
cd helloworld/
mkdir -p src/main/scala
sudo gedit src/main/scala/hello.scala

8-running-scala-application-in-eclipse

Put this code:

object Hello {

def main(args : Array[String]) = {
println(“Hello World”)
}
}

Create a build.sbt file inside the helloworld directory.

sudo gedit build.sbt

9-running-scala-application-in-eclipse

Below is a very basic sbt file, where you can add dependencies needed for your application.

sbt package

10-running-scala-application-in-eclipse

This will create the jar file to run this application. Now run this command in order to run your application.

Command: spark-submit –class “Hello” –master local[2] target/scala-2.10/hello-world_2.10-1.0.jar

11-running-scala-application-in-eclipse

Sbt eclipse

The command below will make the project eclipse compatible and you will be able to import this project in eclipse and run it successfully.
Command: sbt eclipse

12-running-scala-application-in-eclipse

Go to Scala IDE , File -> Import

13-running-scala-application-in-eclipse

Select root directory helloworld.

14-running-scala-application-in-eclipse

You can now see that you can import this project by clicking on Finish.

15-running-scala-application-in-eclipse

Now, let’s run it as Scala application.

16-running-scala-application-in-eclipse

Just FYI, when you are setting SparkConf, always remember to set Master as below.

17-running-scala-application-in-eclipse

Now you can run your application.

18-running-scala-application-in-eclipse

Got a question for us? Please mention it in the comments section and we will get back to you.

Related Posts:

Get Started with Apache Spark and Scala

Apache Spark Vs Hadoop MapReduce

5 Reasons to Learn Apache Spark

Apache Kafka with Spark Streaming: Real-Time Analytics Redefined

About Author
Awanish
Published on Feb 18,2016
Awanish is a Sr. Research Analyst at Edureka. He has rich expertise in Big Data technologies like Hadoop, Spark, Storm, Kafka, Flink. Awanish also holds good knowledge on Devops tools like Git, Jenkins, Docker, Puppet, Nagios. He is passionate about new technologies which provide realistic solutions.

Share on

Browse Categories

Comments
2 Comments