【问题标题】:Unable to debug Flink example in Visual Studio due to absence of mainClass由于缺少 mainClass,无法在 Visual Studio 中调试 Flink 示例
【发布时间】:2020-09-27 21:11:21
【问题描述】:

我的目标是调试此代码以查看它实时,如tutorial 中所建议的那样。

我的 IDE 是 Visual Studio Code,这个例子的语言是 Java。我正在运行 Flink Datastream API 教程。

当我在任何一行设置断点时,我得到以下错误:

Cannot find a class with the main method in the folder 'frauddetection'.

有人提示我创建了一个 launch.json 文件,所以,这就是我创建的:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch) - Current File",
            "request": "launch",
            "mainClass": "FraudDetectionJob"
        }
    ]
}

即使在配置了上述文件并指定了mainClass 之后,我在调试器终端中也遇到了同样的错误:

Error: Could not find or load main class FraudDetectionJob

我尝试执行的代码如下:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package spendreport;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.walkthrough.common.sink.AlertSink;
import org.apache.flink.walkthrough.common.entity.Alert;
import org.apache.flink.walkthrough.common.entity.Transaction;
import org.apache.flink.walkthrough.common.source.TransactionSource;

/**
 * Skeleton code for the datastream walkthrough
 */
public class FraudDetectionJob {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStream<Transaction> transactions = env
            .addSource(new TransactionSource())
            .name("transactions");

        DataStream<Alert> alerts = transactions
            .keyBy(Transaction::getAccountId)
            .process(new FraudDetector())
            .name("fraud-detector");

        alerts
            .addSink(new AlertSink())
            .name("send-alerts");

        env.execute("Fraud Detection");
    }
}

如何调试这个文件?

【问题讨论】:

    标签: java visual-studio-code apache-flink flink-streaming


    【解决方案1】:

    我相信您无法编译和运行该应用程序。在您的pom.xml 中,这是导致问题的原因

    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
        <version>${flink.version}</version>
        <scope>provided</scope>
    </dependency>
    

    将范围更改为compile 以解决此问题。另外,更多技术信息here

    -- 我是如何找到问题的--

    我尝试运行教程中的示例(在 Intellij IDEA 中)并得到与您类似的错误:

    Error: Unable to initialize main class spendreport.FraudDetectionJob
    Caused by: java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/functions/source/SourceFunction
    

    在进一步搜索中,我发现了类似的answer

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 2021-10-30
      • 2013-08-20
      • 1970-01-01
      • 2016-06-22
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多