Project Setup

Dependency

You can quickly get started building a Stateful Functions applications by adding the statefun-sdk to an existing project or using the provided maven archetype.

  1. <dependency>
  2. <groupId>org.apache.flink</groupId>
  3. <artifactId>statefun-sdk</artifactId>
  4. <version>2.1.0</version>
  5. </dependency>

Maven Archetype

  1. $ mvn archetype:generate \
  2. -DarchetypeGroupId=org.apache.flink \
  3. -DarchetypeArtifactId=statefun-quickstart \
  4. -DarchetypeVersion=2.1.0

This allows you to name your newly created project. It will interactively ask you for the groupId, artifactId, and package name. There will be a new directory with the same name as your artifact id.

  1. $ tree statefun-quickstart/
  2. statefun-quickstart/
  3. ├── Dockerfile
  4. ├── pom.xml
  5. └── src
  6. └── main
  7. ├── java
  8. └── org
  9. └── apache
  10. | └── flink
  11. └── statefun
  12. └── Module.java
  13. └── resources
  14. └── META-INF
  15. └── services
  16. └── org.apache.flink.statefun.sdk.spi.StatefulFunctionModule

The project contains four files:

  • pom.xml: A pom file with the basic dependencies to start building a Stateful Functions application.
  • Module: The entry point for the application.
  • org.apache.flink.statefun.sdk.spi.StatefulFunctionModule: A service entry for the runtime to find the module.
  • Dockerfile: A Dockerfile to quickly build a Stateful Functions image ready to deploy.

We recommend you import this project into your IDE to develop and test it. IntelliJ IDEA supports Maven projects out of the box. If you use Eclipse, the m2e plugin allows to import Maven projects. Some Eclipse bundles include that plugin by default, others require you to install it manually.

Build Project

If you want to build/package your project, go to your project directory and run the mvn clean package command. You will find a JAR file that contains your application, plus any libraries that you may have added as dependencies to the application: target/<artifact-id>-<version>.jar.