Using Java language

The process of creating Java function depends on OpenWhisk. You must use JDK8 to compile.

You must write the main method that has the exact signature as follows.

public static JsonObject main(JsonObject args)

Import the following package called google-gson.

import com.google.gson.JsonObject;

Create a java file called Hello.java

import com.google.gson.JsonObject;

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;
    }
}

Compile a Hello.java into a JAR file called hello.jar. google-gson must exist in your Java CLASSPATH when compiling the Java file.

javac Hello.java
jar cvf hello.jar Hello.class

Create a function called function1. You need to specify the name of the main class using --main.

meteoroid function create function1 hello.jar --language java --main Hello

Using Python language

The process of creating Python function depends on OpenWhisk.

Python function is a top-level function called main, create a file called hello.py.

def main(args):
    name = args.get("name", "stranger")
    greeting = "Hello " + name + "!"
    print(greeting)
    return {"greeting": greeting}

Create a function.

meteoroid fucntion create function1 hello.py

If you want to use other entry methods, you must specify the method name using --main.