Introduction

This tutorial will show you how to deploy your Java app in several minutes. These instructions will also give you enough information to make the most out of Dokkur.

Be sure that you already have:

  1. Dokkur account.
  2. SSH keys added to your account.
  3. Java 8 installed locally.
  4. Maven 3 installed locally.

Set up

In this step you will install the Dokkur Toolbelt that gives you you access to the Dokkur Command Line Interface (CLI).

After installation you can use dokkur login command to log in with your email and password you set when creating Dokkur account.

Prepare the app

To deploy an app you need to have the app prepared for deployment.

If you don’t have your own Java project, you can use a template that we have already prepared for you:

$ git clone https://github.com/dokkur/java-getting-started.git
$ cd java-getting-started

You now have a functioning git repository that contains a simple application as well as a pom.xml file, which is used by Java’s dependency manager, Maven.

If you have a Java app that you want to deploy, you need to do some preparations.

Declare app dependencies

How does Dokkur recognize an app as a Java app? The answer is by the existence of a pom.xml file in the root directory. You can create it by running mvn archetype:create.

It may look something like this:

  <dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-template-freemarker</artifactId>
<version>2.0.0</version>
</dependency>
...
</dependencies>

The pom.xml file lists the app dependencies together with their versions. When an app is deployed, Dokkur reads this file and installs the appropriate Java dependencies using the mvn clean installcommand.

Another file, system.properties, determines the version of Java to use. The contents of this file, which is optional, is quite straightforward:

java.runtime.version=1.8

Run mvn clean install in your local directory to install the dependencies, preparing your system for running the app locally.

$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.pom (5 KB at 14.9 KB/sec)
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.584s
[INFO] Finished at: 2015-07-06T09:52:33+01:00
[INFO] Final Memory: 19M/222M
[INFO] ------------------------------------------------------------------------

If you do not have Maven installed, or get an error like “‘mvn’ is not recognized as an internal or external command”, then you can use the wrapper command instead by running mvnw clean install on Windows or ./mvnw clean install on Mac and Linux. This will both install Maven and run the Maven command.
The Maven process copies dependencies into your application’s target/dependency directory. This process is called “vendoring”, and it is accomplished by the following plugin configuration in the pom.xml file.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>

Once dependencies are installed, you will be ready to run your app locally.

Create a new app

Follow these steps:

  1. Open website, go to Personal apps (left menu bar)
  2. Click ⨁ button to open New App interface
  3. Enter the app’s name (Caution! Use latin lowercase and numbers, e.g. myapp007), choose available and convenient instances for hosting, pick Custom App template and press Create App button.

Congrats! Your app has easily been created. Now you need to deploy it. Just do it!

Add BUILDPACK_URL config var

  1. Go to Settings page, in Environmental variables section click on Edit button.
  2. Choose ADD NEW VARIABLE
  3. In the Name field write BUILDPACK_URL
  4. In the VALUE field put
    https://github.com/dokkur/buildpack-java
  5. Save settings

Deploy your app

  1. Go to Settings page, copy the app git url from the Git URL section.
  2. Switch to Dokkur Toolbelt and execute this command:

    git remote add dokkur git_url
    Instead of git_url paste your app's git url.

  3. Push your app:
    git push dokkur master
    If you want to deploy another branch, run:
    git push dokkur yourbranch:master

Hell yeah! Your app is deployed! Open yourappname.dokkurapp.com in your browser.