The process of creating Java actions is similar to that of other actions. The following sections guide you through creating and invoking a single Java action, and demonstrate how to bundle multiple files and third party dependencies.
In order to compile, test and archive Java files, you must have a JDK 8 installed locally.
A Java action is a Java program with a method called
main that has the exact signature as follows:
For example, create a Java file called
Hello.java with the following content:
Hello.java into a JAR file
hello.jar as follows:
Note: google-gson must exist in your Java CLASSPATH when compiling the Java file.
You can create a OpenWhisk action called
helloJava from this JAR file as
When you use the command line and a
.jar source file, you do not need tospecify that you are creating a Java action; the tool determines that from the file extension.
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.,
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,
Find out more about parameters in the Working with parameters section.
Large portions of this page is copied from the Apache OpenWhisk documentation on April 23rd 2021 - where there have been customisations to match Hypi's deployment this has been noted. Apache OpenWhisk and the Apache name are the property of the Apache Foundation and licensed under the Apache V2 license .