Over a million developers have joined DZone.

Getting started with Scala on Jelastic

DZone's Guide to

Getting started with Scala on Jelastic

· Cloud Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

Scala programming language, which also operates on the JVM, can play nicely with many of the operational and monitoring tools as well as with Java and other languages. Scala shares many simple and readable syntax features of other programming languages. It has various productivity advantages and allows developers to work more effectively. Developers often characterize Scala as a more functional language than Java. Actually it’s a mix of object-oriented and functional programming. Such languages like Scala often attract flexible, highly skilled and innovative developers, which form great technical teams. So, let’s see how this highly flexible language works in the cloud!

Create environment

1. Log in into Jelastic and click on the Create environment button.

2. Create your environment in Jelastic e.g. with Tomcat 7 and Java 7.

scala environment

Create application

1. First of all download and install sbt for your OS. It is s a build tool for Scala and Java projects.

2. Now let’s create a simple Scala servlet application for testing. Helloworld.scala (src/main/scala/helloworld.scala)file will look like:

import javax.servlet.http._
class HelloWorldServlet extends HttpServlet {
                override def doGet(req: HttpServletRequest, resp: HttpServletResponse) = {
                resp.getWriter().print("Hello World!")

3. In the src/main/webapp directory create web.xml file for your project:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

Build and deploy project


1. Add special plugin for WAR file building, xsbt-web-plugin, toproject/plugins.sbt:

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.3.0")

2. Create build.sbt file in the base directory of your project. Specify the name of your app, its version, version of Scala and inject the plugin settings:

name := "helloworld"
version := "1.0"
scalaVersion := "2.9.2"
seq(webSettings :_*)
libraryDependencies ++= Seq(
 "javax.servlet" % "servlet-api" % "2.5",
 "org.mortbay.jetty" % "jetty" % "6.1.22" % "container"

Note:  Blank lines are required in order to separate each item.

3. Create a file build.properties in the basedirectory and specify sbt version in there in order to avoid any potential confusion:


4. Run the next command from inside of your base directory in order to build a WAR file:


The WAR archive you have just generated will be stored in thetarget/scala-x.x.x directory.

5. Go back to the Jelastic dashboard and upload your WAR package to the Deployment Manager.

scala upload

6. Deploy your Scala application to the environment you’ve just created.

scala deploy

Sbt-jelastic-deploy plugin

1. Add special plugin for Jelastic to your project for further its deployment. Sbt-jelastic-deploy plugin depends on xsbt-web-plugin and deploys WAR archive, generated by xsbt-web-plugin to the Jelastic environment. To enable sbt-jelastic-deploy specify the appropriate setting in your plugins.sbt (project/plugins.sbt) file:

addSbtPlugin("com.github.casualjim" % "sbt-jelastic-deploy" % "0.1.2")

2. Navigate to your project base directory and create build.sbt file. Specify the name of your app, its version, version of Scala and specify the keys for Jelastic plugin.

import JelasticKeys._
name := "helloworld"
version := "1.0"
scalaVersion := "2.9.2"
seq(webSettings :_*)
libraryDependencies ++= Seq(
 "javax.servlet" % "servlet-api" % "2.5",
 "org.mortbay.jetty" % "jetty" % "6.1.22" % "container"
email in deploy := "your_email_address"
password in deploy := "your_jelastic_password"
apiHoster := "your_hoster's_api"
environment in deploy := "your_jelastic_environment_name"
context in deploy := "context_for_your_app"

Note:  Blank lines are required in order to separate each item.

3. Create a file build.properties in helloworld directory and specify sbt version in there in order to avoid any potential confusion:

sbt.version = 0.12 . 4

4. Use the upload task to build a WAR file and upload it to the Jelastic Deployment Manager for further its deployment. Use deploy task to build a WAR file, upload and deploy it to the specified environment and context.

>sbt upload
>sbt deploy

Voila! See your Scala app in the the Cloud!

scala app in the cloud

This was just a simple example to show you how to get started. You can use any of the mentioned above plugins for creating your Scala WAR package and deploying it to your environment. If you have any questions regarding this topic please let us know in the comment section below.

Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.


Published at DZone with permission of Marina Sprava, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}