IDEA 建立 maven flink项目
建立明细
1 环境检查
2.使用IDEA创建项目
3.pom.xml文件添加对应版本依赖
4 建立new projet
1 环境检查
进入cmd,输入java -version查看java版本和安装情况,输入 mvn version 查看是否安装maven。
2. 使用IDEA创建Flink项目
- 新建项目 new projet,选择Maven,查看JDK版本。然后NEXT。
2.进入 NEXT,输入项目名,存放地址,GroupeId等信息,如图所示。
3.点击 Finish
3. pom.xml文件
-
添加对应版本依赖——介绍添加方法
-
插件(编译,打包)
版本对应关系
建立完成后出现pom.xml文件,添加依赖,清单如下:
-
flink与scala,
https://mvnrepository.com/artifact/org.apache.flink/flink-scala -
flink与streaming(因为项目关于flink的流式处理)
https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-scala
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_2.11</artifactId>
<version>1.12.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-scala -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_2.11</artifactId>
<version>1.12.3</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>1.12.3</version>
</dependency>
</dependencies>
添加方法
以添加flink与scala为例,进入网站mvnrepository.com/artifact/or…
选择对应的版本进入,比如我的flink版本是1.12.3,scala版本是2.11,点击进入,在这个页面中直接复制maven中的依赖到pom.xml文件中,别忘了前后加
<dependencies> XXX XXX </dependencies>
插件(编译,打包)
compile编译,make-assembly打包。
<build>
<plugins>
<!-- 该插件用于将 Scala 代码编译成 class 文件 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.6</version>
<executions>
<execution>
<!-- 声明绑定到 maven 的 compile 阶段 -->
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
出现问题,点击安装一下.
jar-with-dependencies打包jar包,将所有依赖都打包了。
找到maven,更新一下(第一个按钮),发现dependencies都安装好了。
assembly和compiler都安装好了,包括scala等。
建立new projet
在项目中的src文件夹,右键--new--directory--名字自定义XX。
在新建的XX,右键--make directory as-- test sources root
在新建的XX,右键--new--scala class
开始进行项目吧~~