Skip to content
Apache OpenWhisk runtime for Java language functions.
Java Scala Python Shell Dockerfile Makefile
Branch: master
Clone or download
dgrove-oss and rabbah gradlew licensing (#94)
Update gradlew[.bat] scripts from Gradle v5.5 release which
have proper Apache license headers and add corresponding
entry to LICENSE.txt.
Latest commit 9ebb05f Jul 31, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github replace github refs openwhisk to apache (#2236) May 15, 2017
core gradlew licensing (#94) Aug 1, 2019
gradle Update all files using Mini license header to use full ASF header (#87) Jun 14, 2019
tests Update all files using Mini license header to use full ASF header (#87) Jun 14, 2019
.gitattributes Refactor tests, update changelog (#39) Apr 26, 2018
.gitignore Actionloop java (#84) May 12, 2019
.scalafmt.conf Update all files using Mini license header to use full ASF header (#87) Jun 14, 2019
.travis.yml change travis builds to publish docker images with tag 'nightly' (#88) Jun 29, 2019
LICENSE.txt gradlew licensing (#94) Aug 1, 2019
NOTICE.txt update end year to 2019 (#79) Mar 4, 2019 Remove Incubat(ing, ion, or) from docs (#89) Jul 29, 2019
build.gradle Last files to need ASF License headers. (#54) May 23, 2018
gradlew.bat gradlew licensing (#94) Aug 1, 2019
settings.gradle Actionloop java (#84) May 12, 2019

Apache OpenWhisk runtimes for java

Build Status


Quick Java Action

A Java action is a Java program with a method called main that has the exact signature as follows:

public static main(;

For example, create a Java file called with the following content:


public class Hello {
    public static JsonObject main(JsonObject args) {
        String name = "stranger";
        if (args.has("name"))
            name = args.getAsJsonPrimitive("name").getAsString();
        JsonObject response = new JsonObject();
        response.addProperty("greeting", "Hello " + name + "!");
        return response;

In order to compile, test and archive Java files, you must have a JDK 8 installed locally.

Then, compile into a JAR file hello.jar as follows:

jar cvf hello.jar Hello.class

Note: google-gson must exist in your Java CLASSPATH when compiling the Java file.

You need to specify the name of the main class using --main. An eligible main class is one that implements a static main method as described above. If the class is not in the default package, use the Java fully-qualified class name, e.g., --main com.example.MyMain.

If needed you can also customize the method name of your Java action. This can be done by specifying the Java fully-qualified method name of your action, e.q., --main com.example.MyMain#methodName

Create the Java Action

To use as a docker action:

wsk action update helloJava hello.jar --main Hello --docker openwhisk/java8action

This works on any deployment of Apache OpenWhisk

To use on a deployment of OpenWhisk that contains the runtime as a kind:

wsk action update helloJava hello.jar --main Hello --kind java:8

Invoke the Java Action

Action invocation is the same for Java actions as it is for Swift and JavaScript actions:

wsk action invoke --result helloJava --param name World
      "greeting": "Hello World!"

Local development

./gradlew core:java8:distDocker

This will produce the image whisk/java8action

Build and Push image

docker login
./gradlew core:java8:distDocker -PdockerImagePrefix=$prefix-user

Deploy OpenWhisk using ansible environment that contains the kind java:8 Assuming you have OpenWhisk already deploy locally and OPENWHISK_HOME pointing to root directory of OpenWhisk core repository.

Set ROOTDIR to the root directory of this repository.

Redeploy OpenWhisk

cd $OPENWHISK_HOME/ansible
ANSIBLE_CMD="ansible-playbook -i ${ROOTDIR}/ansible/environments/local"
$ANSIBLE_CMD setup.yml
$ANSIBLE_CMD couchdb.yml
$ANSIBLE_CMD initdb.yml
$ANSIBLE_CMD wipe.yml
$ANSIBLE_CMD openwhisk.yml

Or you can use wskdev and create a soft link to the target ansible environment, for example:

ln -s ${ROOTDIR}/ansible/environments/local ${OPENWHISK_HOME}/ansible/environments/local-java
wskdev fresh -t local-java


Install dependencies from the root directory on $OPENWHISK_HOME repository

./gradlew install

Using gradle to run all tests

./gradlew :tests:test

Using gradle to run some tests

./gradlew :tests:test --tests *ActionContainerTests*

Using IntelliJ:

  • Import project as gradle project.
  • Make sure working directory is root of the project/repo

Using container image to test

To use as docker action push to your own dockerhub account

docker tag whisk/java8action $user_prefix/java8action
docker push $user_prefix/java8action

Then create the action using your the image from dockerhub

wsk action update helloJava hello.jar --main Hello --docker $user_prefix/java8action

The $user_prefix is usually your dockerhub user id.


Apache 2.0

You can’t perform that action at this time.