Hi everyone! I'm facin some problems running Flink...
# troubleshooting
l
Hi everyone! I'm facin some problems running Flink with Kotlin. Can someone give me some tips? I tried to create the maven project with the suggested comand by documentation and convert it to Kotlin code with Intellij IDEA, but without success. I get the following error.
Copy code
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/environment/StreamExecutionEnvironment
	at spendreport.FraudDetectionJob.main(FraudDetectionJob.kt:34)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 1 more
d
Is this running in IDE or when deploying to a Flink cluster? When running in IDE you need to include flink-streaming-java, which already provided on the Flink cluster
l
in IDE. But before converting to Kotlin this error did not happen. I started the project with the following command:
Copy code
mvn archetype:generate \
    -DarchetypeGroupId=org.apache.flink \
    -DarchetypeArtifactId=flink-walkthrough-datastream-java \
    -DarchetypeVersion=1.17.1 \
    -DgroupId=frauddetection \
    -DartifactId=frauddetection \
    -Dversion=0.1 \
    -Dpackage=spendreport \
    -DinteractiveMode=false
This is my pom.xml
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <scope>provided</scope>
</dependency>
d
You need to remove the
<scope>provided</provided>
when running in the IDE. Put it back for building Uber jars. Or setup maven profile for IDE that differs to your build
l
Why does this line work with the Java version but not with the Kotlin version?
I have received another error.
Copy code
Exception in thread "main" java.lang.IllegalStateException: No ExecutorFactory found to execute the application.
	at org.apache.flink.core.execution.DefaultExecutorServiceLoader.getExecutorFactory(DefaultExecutorServiceLoader.java:88)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.getPipelineExecutor(StreamExecutionEnvironment.java:2717)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.executeAsync(StreamExecutionEnvironment.java:2194)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:2084)
	at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:68)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:2058)
	at spendreport.FraudDetectionJob.main(FraudDetectionJob.kt:45)
d
Do you have flink-clients dependency too?
Why does this line work with the Java version but not with the Kotlin version?
It shouldn't work with the java version, so not sure
l
Removing
<scope>provided</provided>
from
flink-clients
works fine.
πŸ‘ 1
I think that the Java version works for this reason, but I can't do the same in the Kotlin version.
Copy code
Running the project in an IDE may result in a java.lang.NoClassDefFoundError exception. This is probably because you do not have all required Flink dependencies implicitly loaded into the classpath.

    IntelliJ IDEA: Go to Run > Edit Configurations > Modify options > Select include dependencies with "Provided" scope. This run configuration will now include all required classes to run the application from within the IDE.
https://nightlies.apache.org/flink/flink-docs-release-1.17/docs/try-flink/datastream/#running-in-an-ide
d
Ah good to know.
l
a
As a workaround for Kotlin you can manually define run configuration as java application and using this option there.
l
How to do this exactly?
a
In Intellij Run/Debug configuration window add manually add new
Application
configuration and set main class as
<package>.<filename>Kt
. Everything else is same as in Java.