Search code examples
scalaintellij-ideaapache-flinkflink-streaming

"Stream Processing with Apache Flink" how to run book code from IntelliJ?


As described in this post I have been unable to successfully run any code from the book "Stream Processing with Apache Flink, including the precompiled jar.

It is not my practice to use an IDE but I thought I would try to use IntelliJ as Chapter 3 "Run and Debug Flink Applications in an IDE" describes how to do that specifically for the code for this book.

The book describes a project import process that I have not found a way to use. It describes setting options on import, for example select Maven. I have not found a way to set any options on import.

I am able to import a project and run code. The code fails, looks like with missing dependency. Maybe because it isn't a Maven project?

Here are steps to reproduce

git clone https://github.com/streaming-with-flink/examples-scala.git

Start IntelliJ

enter image description here

Choose "Open or Import" and Select the "examples-scala/" folder. The project imports with no chance to select options.

Now I have a project

enter image description here

Browse to AverageSensorReadings class, open, and run.

enter image description here

Errors with

java.lang.NoClassDefFoundError: org/apache/flink/api/common/typeinfo/TypeInformation

enter image description here

How can I run this code in IntelliJ?


Solution

  • I see that flink dependencies have provided scope in Maven - this means that thay are not included into the classpath when you running the application. Most likely the application is meant to be run on environment where these dependencies already exist (e.g. Hadoop). To be able to run it from from IDE set Include dependencies with "Provided" scope option in Run Configuration:

    enter image description here