準(zhǔn)備
Maven 3.0.4 (或更高版本)和 安裝 Java 8.x
cmd
mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-scala -DarchetypeVersion=1.6.2
#若只使用Java
#mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.6.2
image.png
或者 git clone https://github.com/liangriyu/flink-quickstart.git
一嘶卧、IntelliJ IDEA配置
1有缆、安裝Scala插件
1、Go to IntelliJ plugins settings (IntelliJ IDEA -> Preferences -> Plugins) and click on “Install Jetbrains plugin…”.
2佃却、Select and install the “Scala” plugin.
3葱她、Restart IntelliJ
2续室、導(dǎo)入flink項(xiàng)目
啟動(dòng)idea或者全部關(guān)閉當(dāng)前打開項(xiàng)目(file->Close Project),選擇“Import Project”->maven
image.png
二磨确、測(cè)試運(yùn)行及打包
- 通常情況下锋恬,在IDEA中編寫完代碼直接運(yùn)行main方法測(cè)試程序即可滔岳。
- 打jar包部署到flink集群:
方式1:直接使用maven插件管理(推薦)
<plugins>
<!-- Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<!-- We use the maven-shade plugin to create a fat jar that contains all necessary dependencies. -->
<!-- Change the value of <mainClass>...</mainClass> if your program entry point changes. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.flink:force-shading</exclude>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>log4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<!-- Do not copy the signatures in the META-INF folder.
Otherwise, this might cause SecurityExceptions when using the JAR. -->
<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>org.apache.flink.StreamingJob</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
方式2:手動(dòng)加入依賴(如下)
file ->ProjectStructrue ->Artifacts