cf-java-client Build Status

This is a fork of the 1.1.4.RELEASE version of the official Cloud Foundry Java client ( It has been modified to include several bugfixes and improvements.


The cf-java-client project is a Java language binding for interacting with a Cloud Foundry instance. It provides similar functionality to the Cloud Foundry command line client (, such as creating services and applications, binding services to applications or even registering service brokers. It communicates with the Cloud Foundry Controller by making HTTP requests to the controller's REST API, which is documented at


In addition to the actual client, the official cf-java-client repository contains a Maven and a Gradle plugin for deploying and managing applications through Maven goals and Gradle tasks respectively. However, since we've made no changes to these plugins, they've been removed from this fork entirely. The client implementation is the only remaining component and it can be found under the cloudfoundry-client-lib subdirectory.


In order to use this client in your application, you need to include the following dependency in your pom.xml:


The following is a very simple sample application that connects to a Cloud Foundry instance, logs in, and displays some information about the Cloud Foundry account. When running the program, provide the Cloud Foundry target API endpoint, along with a valid user name and password as command-line parameters.

import org.cloudfoundry.client.lib.CloudCredentials;
import org.cloudfoundry.client.lib.CloudFoundryClient;
import org.cloudfoundry.client.lib.domain.CloudApplication;
import org.cloudfoundry.client.lib.domain.CloudService;
import org.cloudfoundry.client.lib.domain.CloudSpace;


public final class JavaSample {

    public static void main(String[] args) {
        String target = args[0];
        String user = args[1];
        String password = args[2];

        CloudCredentials credentials = new CloudCredentials(user, password);
        CloudFoundryClient client = new CloudFoundryClient(credentials, getTargetURL(target));

        for (CloudSpace space : client.getSpaces()) {
            System.out.printf("  %s\t(%s)%n", space.getName(), space.getOrganization().getName());

        for (CloudApplication application : client.getApplications()) {
            System.out.printf("  %s%n", application.getName());

        for (CloudService service : client.getServices()) {
            System.out.printf("  %s\t(%s)%n", service.getName(), service.getLabel());

    private static URL getTargetURL(String target) {
        try {
            return URI.create(target).toURL();
        } catch (MalformedURLException e) {
            throw new RuntimeException("The target URL is not valid: " + e.getMessage());


Compiling and Packaging

The project is built using Apache Maven and you can use the following command to do so:

mvn clean install

Additionally, the project uses Immutables to generate value objects. As a result, it won't compile in IDEs like Eclipse or IntelliJ unless you also have an enabled annotation processor. See this guide for instructions on how to configure your IDE.


Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.