Search code examples
javajarnoclassdeffounderrorapache-flinkcomplex-event-processing

Java NoClassDefFoundError : Apache Flink Complex Event Processing


I am trying to understand the Apache Flink CEP program to monitor rack temperatures in a data center as described by Flink Official Documentation. But when I follow the steps and create a jar using mvn clean package and tried to execute the package using the command

java -cp "../cep-monitoring-1.0.jar" org.stsffap.cep.monitoring.CEPMonitoring

But I get the following error,

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/functions/source/SourceFunction
    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 sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.functions.source.SourceFunction
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

I tried different variations of giving the classpath as described here but getting the same error. Can someone point out my mistake in running the program?


Solution

  • The cep example uses flink version 1.3.2. So here are the steps to run it.

    1. Install version 1.3.2 of apache flink. (wget it from here and extract it).
    2. cd into flink-1.3.2
    3. ./bin/start-local.sh, this will start the flink cluster. Do cd ...
    4. Clone this repo using git clone and cd into that.
    5. mvn clean package to build the project. This will create target directory.
    6. Run ../flink-1.3.2/bin/flink run target/cep-monitoring-1.0.jar, to start the process.
    7. In separate terminal the output can be logged like this (assuming that you are in same directory as previous step) tail -f ../flink-1.3.2/log/flink-*-jobmanager-*.out (* will be replaced by specific user detail, press tab to autocomplete those).

    Here is the sample output,

    rshah9@bn18-20:~/tools/cep-monitoring-master$ tail -f ../flink-1.3.2/log/flink-rshah9-jobmanager-0-bn18-20.dcs.mcnc.org.out
    TemperatureWarning(9, 102.45860162626161)
    TemperatureWarning(6, 113.21295716135027)
    TemperatureWarning(5, 105.46064102697723)
    TemperatureWarning(0, 106.44635415722034)
    TemperatureWarning(4, 112.07396748089734)
    TemperatureWarning(9, 114.53346561628322)
    TemperatureWarning(3, 109.05305417712648)
    TemperatureWarning(7, 112.3698094257147)
    TemperatureWarning(3, 107.78609416982076)
    TemperatureWarning(9, 107.34373990230458)
    TemperatureWarning(5, 111.46480675461656)