DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Deploying a Scala API on OpenShift With OpenShift Pipelines
  • Configuring SSO Using WSO2 Identity Server
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • 4 Email Validation and Verification Techniques for App Developers

Trending

  • Three Ways AI Is Reshaping DevSecOps
  • Application Integration for IoT Devices: A Detailed Guide To Unifying Your Ecosystem
  • Supercharge Your Software Development Journey With DevOps, CI/CD, and Containers
  • Deploy Like a Pro: Mastering the Best Practices for Code Deployment
  1. DZone
  2. Coding
  3. Languages
  4. Building and Deploying Scala Apps

Building and Deploying Scala Apps

If you've only ever tooled around with Scala in an IDE, here's a quick and easy way to see your app out in the Linux/Mac/Windows worlds.

Alexey Zvolinskiy user avatar by
Alexey Zvolinskiy
·
Jul. 17, 17 · Tutorial
Like (6)
Save
Tweet
Share
16.99K Views

Join the DZone community and get the full member experience.

Join For Free

hey! looks like you're familiar with scala. and i believe you've even developed some apps locally using it. one of coding's main missions is to help people to solve their problems. but how can your apps do this if they are running locally on your laptop? in this post, i want to show the easiest way to deploy a scala application.

how to build a scala project

what do i mean by saying “build” a scala project? well, it means that the project, running locally from the ide, should be “transformed” into something that can be launched from any other environment (linux / windows / mac).

let’s consider a sample scala project. it should be something really simple, so i decided to create a trivial akka-http app. here is its structure:

image title

i used green arrows in order to highlight the files that are important in the context of this article. by walking through the files, we can see what they contain and their purpose. by doing this, i want to work from a particular example to more general one.

almost all scala projects start from a build.sbt file. as a rule, it contains meta information about the project: name, version, dependencies…

name := "sbt-build-example"

version := "1.0"

scalaversion := "2.12.2"

librarydependencies ++= seq(
  "com.typesafe.akka" %% "akka-http" % "10.0.9"
)


take a look at the dependencies in the code above. to be more precise, look at the single dependency. for sure, your project contains more than one. but for this demonstration, it’s enough.

then we have a main class where all “business logic” happens:

package com.example

import akka.actor.actorsystem
import akka.http.scaladsl.http
import akka.http.scaladsl.http.serverbinding
import akka.http.scaladsl.server.directives._
import akka.stream.actormaterializer

import scala.concurrent.future

object main extends app {

    implicit val system = actorsystem()
    implicit val ec = system.dispatcher
    implicit val materializer = actormaterializer()

    val routes = pathprefix("ping") {
        get {
            complete("pong")
        }
    }

    val bindingfuture: future[serverbinding] = http().bindandhandle(routes, "127.0.0.1", 5000)

}


so the demo app has only one endpoint, which returns “pong” when you make a get request to 127.0.0.1/ping

you can check it if you want.

so, how to build this app? how to make it deployable? in order to perform this, we need to add the sbt-native-packager plugin to the project. you can do it by adding a single line of code to the plugins.sbt file.

addsbtplugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0")


then you need to add the following line of code to the build.sbt file as well:

enableplugins(javaapppackaging)


voila!

open terminal/your console, navigate to the root folder of the project, and execute the following command:

sbt stage


this command generates a new folder in your project directory: target/universal/stage/

there are two folders in the stage directory: bin and lib . the first one contains launchers (linux/mac/windows). the second one contains all dependencies and a jar with the application classes.

what’s next? as you may guess, the content of the stage directory can be moved to your server and launched there by executing the following command in the console:

./bin/app-name


notice that this command must be run from the stage folder. by the way, app-name may vary. it depends on the project name (package name) that you specified in the build.sbt file.

summary

as you can see, sbt-native-packager gives a pretty straightforward way to build a scala project. what is really cool is that it provides more packaging options for scala apps. in this article, i described only about 5% of the functionality that this plugin can perform. therefore, i’m going to write a couple of new tutorials about sbt-native-packager .

app Scala (programming language)

Published at DZone with permission of Alexey Zvolinskiy, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Deploying a Scala API on OpenShift With OpenShift Pipelines
  • Configuring SSO Using WSO2 Identity Server
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • 4 Email Validation and Verification Techniques for App Developers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: