You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Flink 1.15.2遇NoClassDefFoundError:找不到StreamTableEnvironment类

问题原因

出现ClassNotFoundException是因为你将flink-table-api-scala-bridge_${scala.compat.version}依赖的scope设置为了provided,这会导致Maven打包时不把该依赖包含到最终的Jar包中。而Flink集群的默认Classpath里并不自带这个Scala桥接依赖,所以运行时找不到StreamTableEnvironment相关类。

解决方案

方案1:调整依赖Scope(推荐)

把flink-table-api-scala-bridge的scope从provided改为compile,这样打包时该依赖会被包含到Jar中:

<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-table-api-scala-bridge_${scala.compat.version}</artifactId>
  <version>1.15.2</version>
  <!-- 移除provided,使用默认compile scope -->
</dependency>

注意:flink-table-planner可以保留provided,因为Flink集群通常已内置该依赖。

方案2:使用Shaded版本依赖

如果担心依赖冲突,可使用Flink提供的shaded版Scala桥接依赖,避免和其他库的类冲突:

<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-table-api-scala-bridge_${scala.compat.version}</artifactId>
  <version>1.15.2</version>
  <classifier>shaded</classifier>
</dependency>

方案3:手动添加依赖到集群

若不想修改打包配置,可下载flink-table-api-scala-bridge_${scala.compat.version}-1.15.2.jar,放到Flink集群每个节点的lib目录下,重启集群后再运行应用。这种方式适合多应用共享该依赖的场景。

方案4:打包成Fat Jar

如果应用包含多个第三方依赖,用Maven的maven-shade-plugin打包成Fat Jar,确保所有依赖都被包含:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.4</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <filters>
              <filter>
                <artifact>*:*</artifact>
                <excludes>
                  <exclude>META-INF/*.SF</exclude>
                  <exclude>META-INF/*.DSA</exclude>
                  <exclude>META-INF/*.RSA</exclude>
                </excludes>
              </filter>
            </filters>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>你的主类完整路径</mainClass>
              </transformer>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

内容的提问来源于stack exchange,提问作者David Ferguson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:31:43