Search code examples
javaapache-flinkmaven-archetype

flink-quickstart-java Exception in thread "main" java.lang.RuntimeException: No data sinks have been created yet


I have just created new Flink project using maven archetype (i.e. template) (Looking at this article)

mvn archetype:generate                               \
      -DarchetypeGroupId=org.apache.flink              \
      -DarchetypeArtifactId=flink-quickstart-java

1.14.4 is current version. The project can compile. But when running either BatchJob or StreamingJob

public class BatchJob {

    public static void main(String[] args) throws Exception {
        // set up the batch execution environment
        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

The first Exception NoClassDefFoundError: org/apache/flink/streaming/api/environment/StreamExecutionEnvironment can be solved as in java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/scala/StreamExecutionEnvironment

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/environment/StreamExecutionEnvironment
    at com.example.flink.StreamingJob.main(StreamingJob.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 1 more

But then I get Exception in thread "main" java.lang.RuntimeException: No data sinks have been created yet.

P.S. All links to documentation https://flink.apache.org/docs/latest from these 2 Java classes are 404 Not Found,
so I guess this maven archetype was in fact abandoned and not updated for some time.

         * Have a look at the programming guide for the Java API:
         *
         * https://flink.apache.org/docs/latest/apis/batch/index.html
         *
         * and the examples
         *
         * https://flink.apache.org/docs/latest/apis/batch/examples.html

Solution

  • The maven quickstart does provide a properly setup skeleton project. However, the supplied applications aren't complete and don't run out of the box because they lack sources and sinks.

    If you define a simple pipeline such as

    env.fromElements(1, 2, 3).print();
    

    then they will work.