本文记录如何在idea里使用搭建最新版flink开发环境,源码在:https://github.com/oneslideicywater/flink-test.git
安装Scala 插件
maven工程
- 新建maven工程
├─src
│ ├─main
│ │ ├─java
│ │ ├─resources
│ │ └─scala
| | |- HelloScala.scala
- 引入scala依赖
选择合适的scala版本, 要和maven工程中
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
3. 引入flink依赖
<properties>
<flink.version>1.14.3</flink.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
- 构建shaded依赖
因为某些原因,有个jar包没有发布到maven仓库。所以需要手动构建:
- 下载git仓库: https://github.com/apache/flink-shaded.git
- 构建命令:
mvn package -Dshade-sources - 本地安装:
cd flink-shaded-zookeeper-parent & mvn install
- 写flink测试代码, 测试开发环境是否有问题
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
object HelloScala {
def main(args: Array[String]): Unit = {
var env=StreamExecutionEnvironment.getExecutionEnvironment
import org.apache.flink.streaming.api.scala._
val stream = env.fromCollection(Array(1,2,3,4,5))
stream.print().setParallelism(1);
env.execute("HelloScala")
}
}
观察结果是否顺利打印出来:
|