创建一个Flink项目

本文档详细介绍了如何搭建Apache Flink 1.5.4的运行环境,包括下载、解压及启动步骤,并展示了如何通过命令行运行WordCount示例程序。此外,还演示了使用Maven创建Flink项目的流程,以及在Eclipse中导入和管理该项目的方法。
摘要由CSDN通过智能技术生成

Flink 环境搭建

下载链接:https://archive.apache.org/dist/flink/flink-1.5.4/

直接下载bin包:flink-1.5.4-bin-hadoop24-scala_2.11.tgz ,解压后启动flink:

jimmy@jimmy-ThinkPad-T420s:~/Downloads/flink-1.5.4/bin$ ./start-cluster.sh 
Starting cluster.
Starting standalonesession daemon on host jimmy-ThinkPad-T420s.
Starting taskexecutor daemon on host jimmy-ThinkPad-T420s.

打开WEB:http://127.0.0.1:8081

运行一个example

./bin/flink run ./examples/batch/WordCount.jar

immy@jimmy-ThinkPad-T420s:~/Downloads/flink-1.9.3$ ./bin/flink run ./examples/batch/WordCount.jar
Starting execution of program
Executing WordCount example with default input data set.
Use --input to specify file input.
Printing result to stdout. Use --output to specify output path.
(a,5)
(action,1)
(after,1)
(against,1)
(all,2)
(and,12)

注:如果example运行不成功,应该是jdk版本不匹配导致

mvn 产生一个flink项目框架

flink版本1.5.4

mvn archetype:generate -DarchetypeCatalog=internal -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.5.4

F:\eclipse-workspace\flink>mvn archetype:generate -DarchetypeCatalog=internal -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.5.4
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[WARNING] Archetype not found in any catalog. Falling back to central repository.
[WARNING] Add a repository with id 'archetype' in your settings.xml if archetype's repository is elsewhere.
Define value for property 'groupId': com.company.test.flink
Define value for property 'artifactId': test-flink
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' com.company.test.flink: :
Confirm properties configuration:
groupId: com.company.test.flink
artifactId: test-flink
version: 1.0-SNAPSHOT
package: com.company.test.flink
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: flink-quickstart-java:1.5.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.company.test.flink
[INFO] Parameter: artifactId, Value: test-flink
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.company.test.flink
[INFO] Parameter: packageInPathFormat, Value: com/company/test/flink
[INFO] Parameter: package, Value: com.company.test.flink
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.company.test.flink
[INFO] Parameter: artifactId, Value: test-flink
[WARNING] CP Don't override file F:\eclipse-workspace\flink\test-flink\src\main\resources
[INFO] Project created from Archetype in dir: F:\eclipse-workspace\flink\test-flink
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  28.866 s
[INFO] Finished at: 2020-09-24T17:06:45+08:00
[INFO] ------------------------------------------------------------------------

F:\eclipse-workspace\flink>

Eclipse导入工程

将maven项目转换成eclipse项目:mvn eclipse:eclipse

jimmy@jimmy-ThinkPad-T420s:~/eclipse-workspace/flink/test-flink$ mvn eclipse:eclipse
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/m2e/lifecycle-mapping/1.0.0/lifecycle-mapping-1.0.0.pom
[WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/m2e/lifecycle-mapping/1.0.0/lifecycle-mapping-1.0.0.jar
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Could not find artifact org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in central (https://repo.maven.apache.org/maven2)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/maven-metadata.xml (741 B at 491 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.10/maven-eclipse-plugin-2.10.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.10/maven-eclipse-plugin-2.10.pom (19 kB at 18 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.10/maven-eclipse-plugin-2.10.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.10/maven-eclipse-plugin-2.10.jar (224 kB at 108 kB/s)
[INFO] 
[INFO] ---------------------< com.test.flink:test-flink >----------------------
[INFO] Building Flink Quickstart Job 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------

file->import->maven->existing maven project

 

在IntelliJ IDEA中创建Apache Flink项目,可以按照以下步骤操作: 1. **打开IntelliJ IDEA**: 打开安装好的IntelliJ IDEA,并确保已经安装了对应版本的Java支持。 2. **新建项目**: 点击菜单栏的 "File" > "New" > "Project",选择 "From Existing Sources" 或者 "Gradle"(如果你打算使用Gradle构建),然后点击 "Next". 3. **选择模板**: 在 "Project SDK" 部分,选择合适的Java版本。如果是从头开始,通常会选当前IDE默认的Java SDK。接着,在 "Project" 标签页下,找到并选择 "JDK",然后勾选 "Create from existing sources" 并浏览到Flink的根目录(如`<FLINK_HOME>`)。 4. **添加模块**: 如果选择的是 "From Existing Sources",你可以手动添加一个新模块,命名为 "flink-project" 或类似名称,选择 "Sources" 类型。如果选择 "Gradle",则需要配置Gradle依赖,引入Flink的库。 5. **配置依赖**: 对于 "From Existing Sources",确保路径下的pom.xml文件或build.gradle文件包含了Flink的依赖项。对于Gradle项目,你需要添加如下依赖: ```groovy implementation 'org.apache.flink:flink-java' implementation 'org.apache.flink:flink-streaming-java' ``` 6. **设置模块结构**: 可以根据需要自定义模块内的目录结构,比如创建 `src/main/java` 和 `src/main/resources` 目录用于存放源代码和资源文件。 7. **运行测试或应用**: 创建完成后,可以在合适的位置编写Flink应用程序或服务,使用IDEA的Run工具进行调试和启动。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值