Host your Scala App with Scalatra and Jelastic Cloud

By November 26, 2015 HowTo No Comments
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone


Applications have come such a long way that nowadays they help us in both working and daily routine tasks. Today we are going to talk about Scalatra, a tiny open-source web micro-framework, written in Scala. It’s most appropriate for construction of RESTful APIs, building high-performance web sites and mobile applications. Being extremely quick and simple, this framework could be considered as one of the best choices for beginners to learn Scala. At the same time, Scalatra is powerful enough to accomplish almost any widely required task thanks to the attachable libraries, which can greatly expand this tool’s basic possibilities.

How you can benefit with Scalatra:

  • fast and easy development of  high-performance, scalable and mobile applications
  • entire  server-side equivalent to in-browser client development frameworks such as backbone.js, ember.js or angular.js
  • possibility  to use available cores of the new 16-core server
  •  access to Scala’s new concurrency-management forms

So, let’s learn how to create and deploy an application into Jelastic Cloud with the help of Scalatra.

Environment Creation

1. To start with, log in to your Jelastic account and click the New environment button in the upper left corner of the dashboard.

publicpreview (1)

2. In the opened environment wizard, choose the Tomcat 7 application server within the Java tab. Define the required amount of resources using the Vertical scaling section, select the preferred environment region and name your environment (e.g. scalatra).

publicpreview (2)

After all the rest of parameters are configured (if needed), click on the Create button at the bottom right corner of the frame.

3. Wait a minute for your environment to be created.

publicpreview (21)

Installing the Required Utilities

For the further operations to be performed, you need to access your account via the Jelastic SSH Gateway, select the appropriate environment (scalatra in our case) and enter your Tomcat 7 container.

publicpreview (4)

Tip: In case you haven’t performed similar operations before, you need to:

1. First of all, after connecting to the shell, add path to the Tomcat /bin folder to the corresponding variable for the comprised scripts to be easily executable:

export PATH
source ~/.bash_profile

publicpreview (22)

2. Now let’s install a few necessary utilities:

  • Conscript represents a plugin, required for building and updating Scala code. Execute the following command in order to download and install it:

curl | sh

publicpreview (8)

  • giter8 is a tool, intended for generating the required project structure (i.e. the hierarchy of directories and files inside) based on project template, fetched from the appropriate Git repo. Get it downloaded using the previously installed Conscript utility:

cs n8han/giter8

publicpreview (9)

3. Once these processes are completed, navigate to the bin folder and download the sbt-launch java-archive. It will install the sbtbuild tool, which represents an interactive shell for the scala-based applications’ building:

cd bin

publicpreview (10)

4. Now create a new sbt file here (using, for example, the vim sbt command) and paste the following lines to it:

SBT_OPTS=”-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M” java $SBT_OPTS -jar `dirname $0`/sbt-launch.jar “$@”

publicpreview (11)

When everything is done, don’t forget to save the changes with typing :wq.

5. The next steps are to set the just added script to be executable by the current user with the chmod command, download and unpack an archive with an example app, and remove its zipped version for not occupying the extra disk space:

chmod u+x sbt
wget; unzip; rm

publicpreview (12)

6. Then, switch to the folder with the Jelastic-dedicated project example and open the comprised build.sbt file (which represents a special Jelastic deployment plugin) for editing:

cd scalatra-website-examples-master/2.4/deployment/scalatra-jelastic
vim build.sbt

publicpreview (13)

7. While inside, substitute the JelasticKeys.apiHoster parameter’s value with your hosting service provider’s domain ( and specify your environment’s name within the JelasticKeys.deploy  parameter (scalatra in our case).

publicpreview (14)

Save the changes and quit from the vim editor with the :wq command.

Note: You need to additionally export your Jelastic login and password to the current user’s profile, as these variables will be required during the further scripts’ running. So, execute the following lines:

export JELASTIC_USERNAME={jelastic_login}
export JELASTIC_PWD={jelastic_password}
source ~/.bash_profile


  • {jelastic_login} – an email address you use to access the Jelastic dashboard
  • {jelastic_password} – the corresponding account password

publicpreview (15)

Build and Deploy an App

Now, as everything is configured, you can proceed to the actual deployment of your project just from the interactive shell.

1. For that, set sbt file to be executable (by means of the chmod command as shown below) and then call this tool to be started:

chmod +x sbt

publicpreview (16)

On the first run, all the required dependencies are to be downloaded, so be patient – it may take some time.

2. Now you can make your project to be built and deployed directly to the Jelastic platform through simply typing the next command inside the shell:

deploypublicpreview (17)

Through the output, you can track how the project and its libraries are uploading to the Jelastic dashboard and deploying to the earlier specified environment.publicpreview (18)

When everything is done, you’ll be shown the corresponding success message with the process duration specified.

3. Now, enter the Jelastic dashboard (or refresh the page if you have it already opened) and click Open in browser for your environment to see what we’ve got:publicpreview (19)

Great! As a result, you’ve just deployed your first example Scalatra app into the Jelastic platform.publicpreview (20)

It was pretty simple, wasn’t it? So, for now you can have fun and learn Scalatra further to create your own stunning apps and get them hosted directly in the Cloud within a few commands! Go ahead and test it by yourself – simply sign up for a 2-week-free-trial and share your experience in the comments below.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone

Leave a Reply

Subscribe to get the latest updates