Jan 05

Using Stork to deploy a production Ninja Framework app

Ninja is a full stack web framework for Java. Stork is an "after-build" tool for Java. Lately, I run all webapps in a stand-alone process (embed Jetty/Netty/etc) and use a reverse proxy (Nginx) to send requests to it. While Ninja is easy to package as a war file that's ready to run in Tomcat/Jboss/etc, it's not as easy to package it as a stand-alone app that can run as a daemon/service. Ninja + Stork to the rescue! Stork integrates with Ninja in just 2 easy steps.

A full demo is available @ https://github.com/fizzed/java-ninja-stork-demo

Step 1: Add Stork Maven Plugin

Stork's maven plugin provides two separate goals. The generate goal binds to the compile phase and compiles any files in src/main/launchers to target/stork. The assembly goal binds to the package phase and creates a tarball of everything -- including the launchers, jars, and resources required to start your Ninja app.

Add the following to your pom.xml:


Step 2: Create Launcher Config File

Stork's maven plugin compiles any files in src/main/launchers to target/stork during the compile phase. Let's say you have an app named "ninja-stork-demo". Create a src/main/launchers directory and add a file named ninja-stork-demo.yml with the following content:

name: "ninja-stork-demo"
domain: "com.fizzed"
display_name: "ninja-stork-demo"
short_description: "Ninja Stork Demo Webapp"
type: DAEMON
main_class: "ninja.standalone.NinjaJetty"
platforms: [ WINDOWS, LINUX, MAC_OSX ]

Compile, Package, Run, Deploy

To verify your launcher config will compile run the following in your terminal:

mvn compile

To assemble your storkified tarball run the following in your terminal:

mvn package

Once maven finishes then target/stork will contain a fully prepared directory with start/stop/run scripts that are ready to run across any platform. Here is what your target/stork directory will look like:

target/stork/lib/(all jars from project including project artifact jar)

To quickly try out your Ninja app on Linux/OSX/UNIX (no need to change dirs):

target/stork/bin/ninja-stork-demo --run

To quickly try out your Ninja app on Windows (no need to change dirs):

target/stork/bin/ninja-stork-demo.bat --run

The target/ directory will also contain a ninja-stork-demo-1.0.0.tar.gz tarball ready to copy to another server. The tarball contains all the necessary scripts to run as a rock-solid, reliable daemon across Windows, Linux, Mac OSX, and many other UNIX platforms.

Since the tarball uses a canonical layout for a Java app, you may also find the stork-fabric-deploy script useful in doing a super efficient deploy to staging/production servers. For more info, you'll want to check out the example app or the Stork Github repository.