package com.day
import org.apache.flink.streaming.api.scala._
object HelloWord {
def main(args: Array[String]): Unit = {
val env = StreamExecutionEnvironment.getExecutionEnvironment
val dataStream = env.fromCollection(List(1, 2, 3, 4))
dataStream.print()
env.execute("HelloJob")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>flink_day</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 属性配置 -->
<properties>
<flink.version>1.11.2</flink.version>
<scope>compile</scope>
</properties>
<dependencies>
<!-- flink 依赖 -->
<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-streaming-scala_2.11</artifactId>
<version>${flink.version}</version>
<scope>${scope}</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- maven 编译 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- 指定编码格式,防止mvn compile命令时会出现的编码错误 -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- scala 编译 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 创建maven工程
- 设置maven依赖,使用阿里云镜像
- 添加Scala模块
- 运行结果