Getting Started with Java

This tutorial will teach you how to build a “Hello, World!” chute using Java and Maven.


Make sure you have Java 1.8+, Maven 3.0+, as well as ParaDrop pdtools (v0.9.2 or newer).

pip install pdtools>=0.9.2

Set up

Use Maven to set up an empty project.

mvn archetype:generate -DartifactId=java-hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd java-hello-world

Create a chute configuration

Use the pdtools interactive init command to create a paradrop.yaml file for your chute.

python -m pdtools chute init

Use the following values as suggested responses to the prompts. If you have a different version of pdtools installed, the prompts may be slightly different.

name: java-hello-world
description: Hello World chute for ParaDrop using Java.
type: light
image: maven
command: java -cp target/java-hello-world-1.0-SNAPSHOT.jar

The end result should be a paradrop.yaml file similar to the following.

command: java -cp target/java-hello-world-1.0-SNAPSHOT.jar
config: {}
description: Hello World chute for ParaDrop using Java.
name: java-hello-world
type: light
use: maven
version: 1

Develop the Application

Replace the automatically-generated application code in src/main/java/org/paradrop/app/ with the following code.




public class App {
    public static void main(String[] args) throws Exception {
        System.out.println("Listening on :8000");
        HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
        server.createContext("/", new GetIndex());

    static class GetIndex implements HttpHandler {
        public void handle(HttpExchange t) throws IOException {
            String response = "Hello, World!";
            t.sendResponseHeaders(200, response.length());
            OutputStream os = t.getResponseBody();

Run the application locally with the following commands.

mvn package
java -cp target/java-hello-world-1.0-SNAPSHOT.jar

Then load http://localhost:8000/ in a web browser to see the result.

Wrap Up

The web server in this application listens on port 8000. We need to include that information in the paradrop.yaml file as well. Use the following command to alter the configuration file.

python -m pdtools chute set config.web.port 8000