By | April 6, 2017

This tutorial will explain you how to create hello-world application using sbt and eclipse plugin.

Step 1 – Download sbt from official website ZIP. You can download .msi file as well this will setup sbt executable path automatically on your windows platform.

If you are downloading ZIP file make sure add sbt/bin path in windows environment variable.
To verify if the sbt is in right path, open cmd and type sbt about 
This will show you the following output. 

C:\>sbt about

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Set current project to root (in build file:/C:/)
[info] This is sbt 0.13.13
[info] The current project is {file:/C:/}root 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.6
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.6

Step 2 – Download scala eclipse ide from official site – Click
Extract the zip file.

Step 3 – Create sbt template
Now on cmd type the following commands

C:\Users\Tushar Sarde>mkdir sbtProject

This will create one dir for you. Now create another folder which will be your sbt project.

C:\Users\Tushar Sarde>cd sbtProject

C:\Users\Tushar Sarde\sbtProject>mkdir myScalaProject

Now cd to myScalaProject directory and crate 3 folders using following command

C:\Users\Tushar Sarde\sbtProject\myScalaProject>mkdir src\main\scala

Now let’s create scala file inside src\main\scala folder

C:\Users\Tushar Sarde\sbtProject\myScalaProject\src\main\scala>echo object myScalaObject { def main(args: Array[String]) = println(“Hello From Toodey !”) } > myScala.scala

Now type dir command on cmd you will see the myScala class created. We need to create “build.sbt” file in “myScalaProject” folder

C:\Users\Tushar Sarde\sbtProject\myScalaProject>notepad build.sbt

name := “myScalaObject”
version := “1.0”
scalaVersion := “2.10.6”




Add the above content into the file, save the file and exit. Now, let’s run the sbt

C:\Users\Tushar Sarde\sbtProject\myScalaProject>sbt run

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Set current project to myScalaObject (in build file:/C:/Users/Tushar%20Sarde/sbtProject/myScalaProject/)
[info] Updating {file:/C:/Users/Tushar%20Sarde/sbtProject/myScalaProject/}myscalaproject...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to C:\Users\Tushar Sarde\sbtProject\myScalaProject\target\scala-2.10\classes...
[info] Running myScalaObject
Hello From Toodey !
[success] Total time: 1 s, completed Apr 6, 2017 10:57:14 AM

Above command will print the output.

Step 4 – Now, let’s make this project as eclipse compatible.

Go to myScalaObject\project directory, create a new file plugins.sbt in it.

C:\Users\Tushar Sarde\sbtProject\myScalaProject\project>notepad plugins.sbt

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

Add the above line in file, save and exit.

Now let’s run the final command, it may start downloading some dependencies.

C:\Users\Tushar Sarde\sbtProject\myScalaProject>sbt eclipse

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\Users\Tushar Sarde\sbtProject\myScalaProject\project
[info] Updating {file:/C:/Users/Tushar%20Sarde/sbtProject/myScalaProject/project/}myscalaproject-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to myScalaObject (in build file:/C:/Users/Tushar%20Sarde/sbtProject/myScalaProject/)
[info] About to create Eclipse project files for your project(s).
[info] Resolving org.scala-lang#scala-compiler;2.10.6 ...
[info] Successfully created Eclipse project files for project(s):
[info] myScalaObject

Now type dir to see all the files.

C:\Users\Tushar Sarde\sbtProject\myScalaProject>dir
 Volume in drive C is Windows
 Volume Serial Number is 3640-0FE8

Directory of C:\Users\Tushar Sarde\sbtProject\myScalaProject

04/06/2017 11:03 AM <DIR> .
04/06/2017 11:03 AM <DIR> ..
04/06/2017 11:03 AM 282 .classpath
04/06/2017 11:03 AM 367 .project
04/06/2017 11:03 AM <DIR> .settings
04/06/2017 10:55 AM 67 build.sbt
04/06/2017 11:03 AM <DIR> project
04/06/2017 10:48 AM <DIR> src
04/06/2017 10:57 AM <DIR> target
 3 File(s) 716 bytes
 6 Dir(s) 73,820,450,816 bytes free

To import this project into eclipse, open eclipse and go to

File > Import > General > Existing project into workspace > Next > Browse > sbtProject > myScalaProject > Finish.

Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *