JAVA Component

Using the JAVA component to run Java code.

The JAVA component allows you to run java code in the standalone version of API Express.


You can read more about Java by the following url
Pay attention that standalone version of API Express uses 8 version of Java so it is recommended to use the same or lower version.

Java Properties

In the JAVA SERVICE section, you can set:

  • Java lib
  • Class name
    In the REQUEST BODY section, you can set:
    JavaScript expression and value of requestBody will be passed as the input parameter in Java component


The JAVA component expects that invoking Java class implements io.appery.apiexpress.components.JavaComponent interface

package io.appery.apiexpress.components;

import com.fasterxml.jackson.databind.node.ContainerNode;

public interface JavaComponent {
    ContainerNode execute(ContainerNode objectNode);

JavaComponent interface has only execute method which accepts ContainerNode object and returns ContainerNode in other words like all API Express components Java component accepts Json object and returns Json object.

Reference Java project with implementation JavaComponent interface is available in git

Main class of reference project is JavaComponentImpl

package io.appery.apiexpress.components;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ContainerNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class JavaComponentImpl implements JavaComponent {
    public ContainerNode execute(ContainerNode containerNode) {

        ObjectMapper mapper = new ObjectMapper();
        ObjectNode result = mapper.createObjectNode();

        result.put("name", containerNode.get("name").textValue());
        result.put("age", 20);

        return result;

JavaComponentImpl expects that input json object contains field with name "name", take value of this field, create new json object with fields name and age.

Reference project contains unit test class JavaComponentTest. It is not essential to create unit class but it is a good practice.

package io.appery.apiexpress.components.tests;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.appery.apiexpress.components.JavaComponentImpl;
import org.junit.Assert;
import org.junit.Test;

public class JavaComponentTest {

    public void testExample() {
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode objectNode = mapper.createObjectNode();
        objectNode.put("name", "alex");

        ObjectNode result = (ObjectNode)new JavaComponentImpl().execute(objectNode);
        Assert.assertEquals(result.get("name").textValue(), "alex");
        Assert.assertEquals(result.get("age").asInt(), 20);

To build a .jar file the mvn package command needs to be run. Pom file of reference project contains all required dependencies and plugin to build proper .jar file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""








maven-shade-plugin plugin copies all class files from dependencies in a result .jar file (which is available after package command in target repository) so result jar file is self-sufficient.

After building .jar file it can be upload in API Expres on the Libs tab.


To run the reference project

  • clone project from git repository
  • run mvn package file
  • upload java-1.0-SNAPSHOT.jar file from target repository and provide name (for example JavaImpl)
  • Create new custom service with only one Java component
  • Specify properties: Java lib: JavaImpl and Class name: io.appery.apiexpress.components.JavaComponentImpl
  • Specify REQUEST BODY as requestBody = {"name": "test"};
  • Save and test service