美文网首页
【flink-开发】IntelliJ IDEA开发

【flink-开发】IntelliJ IDEA开发

作者: 粮忆雨 | 来源:发表于2018-11-13 15:12 被阅读0次

    准备

    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、导入flink项目

    启动idea或者全部关闭当前打开项目(file->Close Project),选择“Import Project”->maven


    image.png

    二、测试运行及打包

    1. 通常情况下,在IDEA中编写完代码直接运行main方法测试程序即可。
    2. 打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:手动加入依赖(如下)
    file ->ProjectStructrue ->Artifacts


    相关文章

      网友评论

          本文标题:【flink-开发】IntelliJ IDEA开发

          本文链接:https://www.haomeiwen.com/subject/dzrkfqtx.html