apacheflink:在预定义的上下文中运行时,不能示例化remoteenvironment

rur96b6h  于 2021-06-24  发布在  Flink
关注(0)|答案(2)|浏览(438)

有人知道,在远程flink集群上运行程序时,以下错误的根源是什么吗?
我该怎么解决?

org.apache.flink.client.program.ProgramInvocationException: The main method caused an error.
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:512)
    at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:395)
    at org.apache.flink.client.program.Client.runBlocking(Client.java:252)
    at org.apache.flink.client.CliFrontend.executeProgramBlocking(CliFrontend.java:675)
    at org.apache.flink.client.CliFrontend.run(CliFrontend.java:326)
    at org.apache.flink.client.CliFrontend.parseParameters(CliFrontend.java:977)
    at org.apache.flink.client.CliFrontend.main(CliFrontend.java:1027)
Caused by: org.apache.flink.api.common.InvalidProgramException: The RemoteEnvironment cannot be instantiated when running in a pre-defined context (such as Command Line Client, Scala Shell, or TestEnvironment)
    at org.apache.flink.api.java.RemoteEnvironment.<init>(RemoteEnvironment.java:118)
    at org.apache.flink.api.java.RemoteEnvironment.<init>(RemoteEnvironment.java:78)
    at org.apache.flink.api.java.ExecutionEnvironment.createRemoteEnvironment(ExecutionEnvironment.java:1155)
    at org.apache.flink.test.myProj.main(myProj.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:497)
    ... 6 more
kokeuurv

kokeuurv1#

要将作业提交到远程环境(您的代码使用.createremoteenvironment),只能通过api调用而不是通过cli来完成

6qftjkof

6qftjkof2#

在flink程序中,您需要使用

ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

检索 ExecutionEnvironment . 这将自动获取本地环境(当您从ide执行时)或集群环境(当您使用命令行客户机时)。
你只会用 RemoteEnvironment ,如果您想向远程集群提交flink程序。

相关问题