How to use SBT with Eclipse scala IDE

Scala is most used language in big data programming.Programmer from java background has used an eclipse IDE for programming. so eclipse also have there scala-ide (http://scala-ide.org/). As eclipse supports more of the maven as a build engine in-order to use SBT here are some tricks.

Those who are not aware about sbt (Simple build tool). SBT is a default build engine tool for scala.

i will show  you  an example of Apache spark. I will try to import a code in eclipse  using sbteclipse plugin.

Lets get started, how to use SBT with Eclipse scala IDE

I have created a shell script which will create default project structure of SCALA language, it will also create a build.sbt file which is require for SBT build engine

#!/bin/sh
mkdir -p src/{main,test}/{java,resources,scala}
mkdir lib project target

# create an initial build.sbt file
echo 'name := "SubscriptionExpiry"
version := "1.0"
scalaVersion := "2.11.8"' > build.sbt

you can also run a shell script on windows machine using CYGWIN (https://www.cygwin.com/)

below script will create you a project structure.

now installing a SBT Eclipse plugin in sbt (https://github.com/typesafehub/sbteclipse).

Go to C:\Users\[username]\.sbt\0.13\plugins\

create a plugins.sbt file. open it with notepad, go to link (https://github.com/typesafehub/sbteclipse),
copy line

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.0.1")
paste it to the plugins.sbt. save it.

open your command prompt
now go to project folder

cd c:\Users\[username]\workspace\[projectname]
sbt reload

note that your internet should be on this time, it will download a plugin.

now open plugins.sbt and add your require dependencies

name := "SubscriptionExpiry"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.0"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.6.0"
libraryDependencies += "com.datastax.spark" %% "spark-cassandra-connector" % "1.5.0-RC1"

open the command prompt


cd c:\Users\[username]\workspace\[projectname]
sbt eclipse

it will download all your dependencies.

for open you scala-ide (Eclipse) and import a project…

that it’s you are done with it

Leave a Reply