flink scala 项目maven编译 (flink报错:Error: Static methods in interface require -target:jvm-1.8 已解决)

问题:

在Flink scala中使用WatermarkStrategy类中的方法maven编译时抛出以下异常

[ERROR] /Users/duzhixin/flink-dw/src/main/scala/come/bigdata/etl/FlinkEvent.scala:26: error: Static methods in interface require -target:jvm-1.8
[INFO]   val eventStream = env.fromSource(kafkaSource,  WatermarkStrategy.noWatermarks[String],"Kafka Source With Custom Watermark Strategy")

在这里插入图片描述

解决:

maven里加上

 <configuration>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
 </configuration>

如下

    <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <configuration>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

完整scala maven build pom.xml如下,net.alchim31.maven 里的scala maven 插件用了会有坑,注释掉了

<build>
        <!--        <sourceDirectory>src/main/scala</sourceDirectory>-->
        <finalName>flink-dw</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <configuration>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--manven打包插件-->
            <!-- 用于打可执行jar包 -->
            <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <classesDirectory>target/classes/</classesDirectory>
                    <archive>
                        <manifestEntries>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <type>jar</type>
                            <includeTypes>jar</includeTypes>
                            <!--<useUniqueVersions>false</useUniqueVersions> -->
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--            <plugin>-->
            <!--                <groupId>net.alchim31.maven</groupId>-->
            <!--                <artifactId>scala-maven-plugin</artifactId>-->
            <!--                <version>4.5.6</version>-->
            <!--                <executions>-->
            <!--                    <execution>-->
            <!--                        <id>scala-compile-first</id>-->
            <!--                        <phase>process-resources</phase>-->

            <!--                        <goals>-->
            <!--                            <goal>compile</goal>-->
            <!--                            <goal>testCompile</goal>-->
            <!--                        </goals>-->
            <!--                    </execution>-->
            <!--                </executions>-->
            <!--                <configuration>-->
            <!--                    <jvmArgs>-->
            <!--                        <jvmArg>-Xms64m</jvmArg>-->
            <!--                        <jvmArg>-Xmx1024m</jvmArg>-->
            <!--                    </jvmArgs>-->
            <!--                    <args>-->
            <!--                        <arg>-nobootcp</arg>-->
            <!--                    </args>-->
            <!--                    <addScalacArgs>-target:jvm-1.8</addScalacArgs>-->
            <!--                    <jvmArgs>1.8</jvmArgs>-->
            <!--                </configuration>-->
            <!--            </plugin>-->
        </plugins>
    </build>

但是如果要在idea里run,还需要单独设置 scala compiler
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值