Deploying a Sample Java Application

Last updated

See Java Applications for details on deploying Java application servers.

This guide provides a simple example of deploying a Java application using Octopus Deploy.

Prerequisites

This guide assumes some familiarity with Octopus Deploy.  You should be able to configure projects and have a Tentacle or SSH deployment target already configured.

Naked scripting allows you to transfer and extract your package on remote targets without the need for Calamari or mono. Read the short guide here for more details.

Sample Application

Here is a sample application that will prompt the user to press a key before exiting:

PressAnyKey.java

public class PressAnyKey {
    public static void main(String[] args) throws java.io.IOException {
        System.out.println("Press any key to continue.");
	System.in.read();
    }
}

Deploying the Application

Step 1: Upload the Application to the Built-in Repository

In order to deploy the application with Octopus Deploy it must be compiled and packaged. This would usually be done by your build server but for the sake of this demonstration let's do it manually.

  1. Compile the application:
javac PressAnyKey.java
  1. Zip PressAnyKey.class into the archive PressAnyKey.1.0.0.zip (you can download a sample: PressAnyKey.1.0.0.zip)
  2. Upload PressAnyKey.1.0.0.zip to the Octopus Deploy built-in feed (Library ➜ Packages or follow the instructions here).

Step 2: Create the Project and Deployment Process

  1. Create a new project called Press Any Key.
  2. Add a Deploy a package step to the deployment process.
  3. Configure the step to deploy the package PressAnyKey.1.0.0.zip.
  4. Configure the step to run a post-deployment script to start the application.

PowerShell

Start-Process java PressAnyKey

Bash

screen -d -m -S "PressAnyKey" java PressAnyKey

The application must be launched in a new process or session so that control returns to the shell. Otherwise the deployment will wait until the application is terminated.

Step 3: Deploy

Create a release and deploy.

The application will be running on the target machine:

ubuntu@ip-10-0-0-245:/$ ps aux | grep 'PressAnyKey'
ubuntu    6544  0.0  0.0  25776  1288 ?        Ss   02:00   0:00 SCREEN -d -m -s PressAnyKey java PressAnyKey
ubuntu    6545  0.0  0.7 2076112 28584 pts/2   Ssl+ 02:00   0:01 java PressAnyKey