Apache Spark and Scala (36 Blogs) Become a Certified Professional

Running Scala Application In Eclipse IDE Using Sbteclipse

Last updated on Jul 15,2021 12.3K Views

Awanish
Awanish is a Sr. Research Analyst at Edureka. He has rich expertise... Awanish is a Sr. Research Analyst at Edureka. He has rich expertise in Big Data technologies like Hadoop, Spark, Storm, Kafka, Flink. Awanish also...

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 or you can also join our Scala Certification today..

Related Posts:

Apache Spark Vs Hadoop MapReduce

5 Reasons to Learn Apache Spark

Apache Kafka with Spark Streaming: Real-Time Analytics Redefined

Comments
2 Comments
  • SR says:

    Running spark word count in scala IDE eclipse with sbt plugin on windows. Getting following error object apache is not a member of package org. And please let me know how to connect spark word count running windows to edureka VM.

  • Amit says:

    Thanks for the blog.. very detailed and very well explained..

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Running Scala Application In Eclipse IDE Using Sbteclipse

edureka.co