Closed qcfu-bu closed 5 months ago
@qcfu-bu thanks for the question.
This is what I usually do to run Scala-based Flink job:
// I do not usually package Scala std library(s) with SBT assembly, so set to "false"
assemblyPackageScala / assembleArtifact := false
Then when you go to run your Flink job in any other mode than local one, i.e. session cluster, application cluster, job cluster:
classloader.parent-first-patterns.default: java.;org.apache.flink.;com.esotericsoftware.kryo;org.apache.hadoop.;javax.annotation.;org.xml;javax.xml;org.apache.xerces;org.w3c;org.rocksdb.;org.slf4j;org.apache.log4j;org.apache.logging;org.apache.commons.logging;ch.qos.logback
It is needed to load Scala from child classloader to avoid loading old Scala 2.12 which is still in the Apache Flink 1.x distribution. Scala 2.12 won't be packaged in the Flink 2.x, so then we do not need to modify this property any more.
Thanks for the reply! But, I'm not quite sure what you mean by add Scala standard library to the dependency classpath. I tried to download the JARs of the scala libraries and put them in the flink/lib
directory as follows
I've added the settings you've written to my build.sbt
and flink-conf.yaml
respectively.
But after submitting the rebuilt JAR to flink, I still get the same error as before.
Can you try two test to see what works better?
flink run --classpath <url>
I've tried both methods.
This example works for me fine: https://github.com/novakov-alexey/flink-sandbox/blob/main/modules/core/src/main/scala/org/example/connectedStreams.scala
flink --version
Version: 1.18.0, Commit ID: a5548cc
> flink run --class org.example.ConnectedStreams ../flink-sandbox/modules/core/target/scala-3.3.1/core-assembly-0.1.0-SNAPSHOT.jar
Job has been submitted with JobID 35ac392accbb978f07034bd6753ffffe
Both Scala libs in the flink/lib folder.
Can you also try it?
I've tried to build JARs using your sandbox repo and submitting them and it still does not work. What's frustrating is that flink clearly sees the 2 scala libraries in the classpath.
I'm giving up on getting this to work. Thanks for the help.
Perhaps try with Docker containers to get some reproducibility.
Following the g8 template, I can run the wordcount example successfully using
sbt run
. However, when I try packaging the code into a fat JAR withsbt assembly
and submitting to a local flink cluster, I run into the following errorThe following are the contents of my
build.sbt
file.