Deploy Java and JVM-Based apps using OpsCaptain

OpsCaptain can deploy Java, Scala and any JVM-Based language and framework. Under the hood, the platform uses the Cloud Foundry battle tested open source java buildpack. From the developers perspective, you simply deploy your code using the CLI and OpsCaptain configures the environment to compile your application using the java buildpack. Knowledge of Cloud Foundry is not required nor do you need to know how the buildpack works unless you want to customize the runtime parameters used to build your application. Click on the buildpack link to learn about how to do this. OpsCaptain provides a Cloud Foundry compatible environment on your own servers so you can run your JVM applications.


Install the opscaptain-cli on your local machine and also log in. If you haven't, run the below commands from your terminal to install it and login:

npm install -g opscaptain-cli opscaptain login -em -pw ******

You must have already added the server that will be used to host your Java app. To add a server to your OpsCaptain account, follow this guide here.

If you do not have a server yet, you can purchase a server or use the free tier or credit from one of the following clouds: AWS EC2, Microsoft Azure, Vultr, DigitalOcean and Google

Step 1. Create your app

From the dashboard: Log into the dashboard and create a new app using this link. Select the required database engine. If your app does not require a database, do not make a selection. Once the app and database are created, you can then proceed to deploy your code to it.

Step 2. Create the ocmanifest.json file in your application directory.

You will typically configure the ocmanifest.json file on your first deployment or when you need to change any environment variables.

The below example shows a sample ocmanifest.json file to deploy Java apps:

{ // The name you provided when creating the app in step 1 name: "jvm-hello-word", // Configure environment variables if any env: { "VARNAME": "VARVALUE" }, buildpacks: ["java"] }

Step 3. Deploy your Jar, War, Dist zip build output

With the exception of Groovy apps which can be deployed as is, you have to first build your application and then push the build output.

Example deploying Grails

// Build the application into a .war file ./grailsw war // Deploy the .war file to your server. opscaptain deploy -p target/grails-application-0.1.war

Example deploying Groovy

The Java Buildpack can run Groovy applications written with the Ratpack framework and from raw .groovy files (no pre-compilation).

opscaptain deploy

Example deploying Java Main

The Java Buildpack can run Java applications with a main() method provided that they are packaged as self-executable JARs

// building with Gradle example: gradle build // Or building with Maven example: mvn package // Finally deploy the JAR to your server and run it: opscaptain deploy -p target/java-main-application-1.0.0.BUILD-SNAPSHOT.jar

Example deploying Play framework

// bundle using play dist and deploy play dist opscaptain deploy -p target/universal/ // bundle using play stage and deploy play stage opscaptain deploy -p target/universal/stage

Example deploying Servlet packaged as a WAR file

gradle build opscaptain deploy -p build/libs/web-servlet-2-application-1.0.0.BUILD-SNAPSHOT.war

Example deploying Spring Boot CLI

// using spring grab spring grab *.groovy opscaptain deploy // using spring jar spring jar spring-boot-cli-application-1.0.0.BUILD-SNAPSHOT.jar *.groovy opscaptain deploy -p spring-boot-cli-application-1.0.0.BUILD-SNAPSHOT.jar