Lightbend Activator

Building native server packages

Building native server packages

July 26, 2014
sbt java scala scaladays2014

Builds debian and rpm packages with startup scripts

How to get "Building native server packages" on your computer

There are several ways to get this template.

Option 1: Choose sbt-native-package-server in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for sbt-native-package-server in the list of templates.

Option 2: Download the sbt-native-package-server project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for sbt-native-package-server.

  1. Download the Template Bundle for "Building native server packages"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\sbt-native-package-server> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a sbt-native-package-server project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME sbt-native-package-server on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

Build native server packages

sbt-native-packager is a plugin to build distributions and native packages like zip, tar, debian, rpm, msi or dmg. It provides a set of "archetypes", which provide settings for different use cases.

This tutorial provides a basic introduction the java_server, which let's you build native debian/rpm packages with autostart scripts and default folders.

  • What's a server application?
  • Example application
  • Build.sbt
  • Installing on debian systems with Upstart
  • Configuration

What's a server application?

The server type is defined by the following settings:

  • A set of default folders like /var/log/[packagename] with best-practices access rights.
  • Autostart scripts which use native service / startup systems like Upstart or SystemV

Example application

The server in this tutorial only logs a message in configurable rate to a log file. We use log4j2 as a logging system and the Typesafe Config Library to configure our server.


// what class starts the server
mainClass in Compile := Some("core.Server")

// include the server settings

// global package settings
packageDescription := "Custom application configuration"

// Maintainer for all packages
maintainer := "Nepomuk Seiler "

packageSummary in Linux := "Logging Server Application"

// Map the default config files to the universal mappings
mappings in Universal <++= sourceDirectory  map { src =>
    val resources = src / "main" / "resources"
    val log4j = resources / "log4j2.xml"
    val reference = resources / "reference.conf"
    Seq(log4j -> "conf/log4j2.xml", reference -> "conf/application.conf")

The last setting needs some explanation. Mappings define a tuple sourcefile -> targetfile. In this case we are adding the log4j2.xml configuration file to all packaging outputs to the conf/log4j2.xml folder, following the universal mapping conventions. The file will be available relative to the installation location.

The same is done with the reference.conf with the exception that we rename the file to fit the Config Library conventions.

Installing on debian systems with Upstart

Let's build and install our server. For debian systems upstart is used by default for starting your application.

sbt debian:packageBin
sudo dpkg -i target/sbt-native-package-server-1.0.deb

You will notice a few things during the installation.

  • A group and a user sbt-native-package-server will be created
  • A service sbt-native-package-server will be started

Try to use the standard service commands to control your application

  • sudo service sbt-native-package-server stop
  • sudo service sbt-native-package-server start
  • sudo service sbt-native-package-server restart
  • sudo service sbt-native-package-server status


Let's take a closer look at our configuration. In the project directory in src/templates/etc-default is the application startscript configuration stored. After installing the package you can find the file under /etc/default/sbt-native-package-server. The start script contains two system properties, which point to the configuration files for log4j and the config library.

Open one of the configuration files as sudo and make a change. For example change the hearbeat.msg value. Then restart the application with sudo service sbt-native-package-server restart, while watching the logging output with tail -f /var/log/sbt-native-package-server/app.log.

Running with Docker

sbt docker:publishLocal
docker run sbt-native-package-server:1.0