Desktop version

Home arrow Computer Science

  • Increase font
  • Decrease font


<<   CONTENTS   >>

Bootstrapping our Play framework app with Activator

Lightband (former Typesafe) has another tool called Activator (https ://www. lightbend. co m/community/core-tools/activator-and-sbt), which is a wrapper on top of SBT. Activator makes it easier to create Reactive applications using Scala, Akka, and the Play framework. Don't worry about the Play framework right now, because we will cover that in greater detail in Chapter 3, Developing the UI with Play Framework. Akka will be covered in detail in Chapter 8, Developing a chat with Akka.

Let's download and install Activator, and Bootstrap our architecture. Remember, we need to have Java 8 and Scala 2.11 already installed. If you don't have Java 8 or Scala 2.11, go back

to Chapter 1, Introduction to FP, Reactive, and Scala and install them.

First of all, you need to download activator from here: https ://www. lightbend.com/activ ator/download

I recommend that you download the minimal package, and let Activator download and install the rest of the other dependencies for you. You can download the minimal package

here: https://downloads.typesafe.com/typesafe-act ivator/1.3.10/typesafe-activa tor-1.3.10-minimal.zip.

For this book, we will be using version 1.3.10. We need to put the activator/bin folder in the OS PATH.If you want, you can install Activator using the terminal, like this:

If you want, you can install Activator using the terminal, like this:

$ cd /usr/local/

$ wget https://downloads.typesafe.com/typesafe- activator/1.3.10/typesafe-activator-1.3.10-minimal.zip $ tar -xzf typesafe-activator-1.3.10-minimal.zip $ rm -rf typesafe-activator-1.3.10-minimal.zip $ sudo echo 'export PATH=$PATH:/usr/local/typesafe-activator- 1.3.10-minimal/bin' >> ~/.bashrc $ source >> ~/.bashrc

In order to test your installation, execute this command:

$ activator new ReactiveWebStore

The preceding command will Bootstrap an architecture for you with Scala, Akka, Play framework, and SBT.

Activator will ask you a series of questions like such as what templates you might like to use. There are a couple of templates for Java applications, Scala applications, Akka applications, and Play applications. For now, we will pick option 6) play-scala.

The first time you run Activator, it could take some time, because it will download all the dependencies from the web. When Activator finishes, you should see a folder called

ReactiveWebStore in your file system.

The command $ activator new ReactiveWebStore shows the following result:

You should enter the ReactiveWebStore folder if you type $ ll into the console, and you should also see the following structure:

diego@4winds:~/bin/activator-1.3.10-minimal/bin/ReactiveWebStore$

ll

total 52

drwxrwxr-x 9 diego diego 4096 Mai 14 19:03 ./

drwxr-xr-x 3 diego diego 4096 Mai 14 19:03 ../

drwxrwxr-x 6 diego diego 4096 Mai 14 19:03 app/

drwxrwxr-x 2 diego diego 4096 Mai 14 19:03 bin/

  • -rw-rw-r— 1 diego diego 346 Mai 14 19:03 build.sbt drwxrwxr-x 2 diego diego 4096 Mai 14 19:03 conf/
  • -rw-rw-r— 1 diego diego 80 Mai 14 19:03 .gitignore drwxrwxr-x 2 diego diego 4096 Mai 14 19:03 libexec/
  • -rw-rw-r— 1 diego diego 591 Mai 14 19:03 LICENSE drwxrwxr-x 2 diego diego 4096 Mai 14 19:03 project/

drwxrwxr-x 5 diego diego 4096 Mai 14 19:03 public/

-rw-rw-r— 1 diego diego 1063 Mai 14 19:03 README

drwxrwxr-x 2 diego diego 4096 Mai 14 19:03 test/

The content is explained as follows:

  • app: This is the Play framework application folder where we will do the Scala web development.
  • build.sbt: This is the build file; as you can see, Activator has generated the SBT build config for us.
  • conf: This holds the application config files such as logging and Scala/Play app config.
  • project: This is the SBT project folder where we define SBT plugins and SBT version.
  • test: This holds the test source code for our application.
  • public: This holds static HTML assets like Images, CSS, and JavaScript code.
  • bin: This holds a copy of the activator script for Linux/Mac and Windows.
  • libexec: This holds the Activator jar. This is pretty useful, because Activator has packed itself with our application. So, let's say you push this application for GitHub - when someone needs to access this app and download it from GitHub, the SBT file will be there, so they won't need to download it from the Internet. This is especially useful when you are provisioning and deploying applications in production, which this book will cover in detail in Chapter 10, Scaling Up.
 
<<   CONTENTS   >>

Related topics