Skip to main content Skip to section navigation
U.S. flag

An official website of the United States government

Code samples

Java app

Learn how to deploy a Java web application in your sandbox.

Install the CloudFoundry command line interface (CLI)

Since cloud.gov is based on the open-source Cloud Foundry project, it uses the Cloud Foundry CLI. Download and install the CLI for your system:

Test your install with following command:

cf help

Deploy the sample app

Now that you have your account and the CLI installed, let’s deploy a Java web application by downloading the application code, connecting to cloud.gov, and “pushing” the application.

Download the application code from cloud.gov’s GitHub repository

If you have Git installed:

git clone https://github.com/cloud-gov/cf-sample-app-spring

cd cf-sample-app-spring

If you don’t have Git installed, download main.zip from the repository, unzip main.zip, then:

cd cf-sample-app-spring-main

Connect to cloud.gov

cf login -a https://api.fr.cloud.gov --sso

Complete the login in your browser at https://login.fr.cloud.gov/passcode. You’ll get a one-time passcode, which you then paste into your terminal.

Push the application

cf push

The push command will upload your sample app, prepare it for cloud.gov, then after a couple minutes tell you what URL to visit in your browser. Look for the routes: line, as in this example output:

cf push

Using manifest file ...

Creating app cf-spring in org / space
OK
...[snip]...
requested state:   started
**routes:          flask-example-fluent-okapi.app.cloud.gov**
last uploaded:     Tue 05 Mar 13:40:39 PST 2019
stack:             cflinuxfs3
buildpacks:        python

state     since #0   running   2017-12-02 12:53:29 PM
View your application

Use your browser to visit the routes: from the push command (in the above example, https://flask-example-fluent-okapi.app.cloud.gov). Your browser should display something like this:

"Cloud Foundry sample application"

Congratulations! You now have a running webapp built on the Java Spring framework.

Exploring other cloud.gov features

Visit the dashboard — https://dashboard.fr.cloud.gov/ — to see your options for managing your application via your browser.

View your application logs with cf logs --recent or with the web-based logviewer at https://logs.fr.cloud.gov

If you’re done, you can delete your app by running cf delete <APPNAME> (it’s up to you whether to keep it running for more experiments or delete it).

Other languages

Try a simple “Hello world” app in .Net Core, PHP, Python, R, Ruby, NodeJS or Clojure in your sandbox.

Install the CloudFoundry command line interface (CLI)

Since cloud.gov is based on the open-source Cloud Foundry project, it uses the Cloud Foundry CLI. Download and install the CLI for your system:

Test your install with following command:

cf help

Deploy a Hello World app

Now that you have your account and the CLI installed, let’s download the “Hello World” samples, choose one, connect to cloud.gov and “push” the application code.

Download the Hello World code examples from cloud.gov’s GitHub repository

If you have Git installed:

git clone https://github.com/cloud-gov/cf-hello-worlds
cd cf-hello-worlds

If you don’t have Git installed, download main.zip from the repository, unzip main.zip, then:

cd cf-hello-worlds-main

Choose a framework

There are subdirectories for a number of different language + framework combinations. Choose an , then

cd <example>

E.g., cd python-flask

Regardless of the framework you choose, the remaining steps are all the same.

Connect to cloud.gov

cf login -a https://api.fr.cloud.gov --sso

Complete the login in your browser at https://login.fr.cloud.gov/passcode. You’ll get a one-time passcode, which you then paste into your terminal.

Push the application

cf push

The push command will upload your sample app, prepare it for cloud.gov, then after a couple minutes tell you what URL to visit in your browser. Look for the routes: line, as in this example output:

cf push

Using manifest file ...

Creating app dotnet-core in org / space
OK
...[snip]...
requested state:   started
**routes:          flask-example-fluent-okapi.app.cloud.gov**
last uploaded:     Tue 05 Mar 13:40:39 PST 2019
stack:             cflinuxfs3
buildpacks:        python

     state     since
#0   running   2017-12-02 12:53:29 PM
View your application

Use your browser to visit the routes: from the push command (in the above example, https://flask-example-fluent-okapi.app.cloud.gov). It should just display Hello World from and the name of your programming language example.

Congratulations! You now have a running web app built on the language and framework of your choice.

Exploring other cloud.gov features

Visit the dashboard — https://dashboard.fr.cloud.gov/ — to see your options for managing your application via your browser.

View your application logs with cf logs --recent or with the web-based logviewer at https://logs.fr.cloud.gov

If you’re done, you can delete your app by running cf delete <APPNAME> (it’s up to you whether to keep it running for more experiments or delete it).

Additional resources

If you’ve run into any issues with these tutorials, please Contact support at cloud.gov. We’re happy to help.

Did we miss a tip or useful resource that you think we should add? Submit a suggestion on GitHub or send us an email.

Additional sample applications

Join the communities

Want more?

Upgrade to a paid package to get full access to the platform and permanent spaces for hosting longer term demos and web applications in production. Email us at inquiries@cloud.gov to learn more about what cloud.gov can do.

cloud.gov

An official website of the U.S. General Services Administration

Looking for U.S. government information and services?
Visit USA.gov