I have written a simple pattern like this
Pattern<JoinedEvent, ?> pattern = Pattern.<JoinedEvent>begin("start")
.where(new SimpleCondition<JoinedEvent>() {
@Override
public boolean filter(JoinedEvent streamEvent) throws Exception {
return streamEvent.getRRInterval()>= 10 ;
}
}).within(Time.milliseconds(WindowLength));
and it executes well in IntellijIdea. I am using Flink 1.3.2 both in the dashboard and in IntelliJ-Idea. While I was building Flink from source, I have seen a lot of warning messages which led me to believe that iterative condition classes have not been included in a jar as error also says ClassNotFoundException
. Below is the error
Caused by: java.lang.NoClassDefFoundError: org/apache/flink/cep/pattern/conditions/IterativeCondition
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at
org.apache.flink.client.program.PackagedProgram.hasMainMethod(PackagedProgram.java:492)
... 38 more
Caused by: java.lang.ClassNotFoundException: org.apache.flink.cep.pattern.conditions.IterativeCondition
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 44 more
After a whole day of my effort to solve this problem, finally, I got the solution. The problem was pretty basic, which is that Flink CEP is not a part of the binary distribution, so whenever I tried to execute pattern it gave me an error.
Solution is simple
As you can see Flink Binary does not have the cep jar.
so go to your IDE which is IntelliJ in my case and copy the required jar
Go to this location and copy paste this jar to lib folder in your binary version.
Yalaa, problem solved
If you dont want to add dependencies manually or you have a maven or sbt project, you can simply add the dependency in the .pom file or corresponding sbt file and add the following dependencies.
Change the flink version according to your project needs.