使用Dataflow生成自我执行JAR

问题描述 投票:1回答:1

根据link中的方向,尝试构建用于在Airflow中调度数据流作业的JAR文件。在依赖项部分中添加了相关依赖项,并在POM文件的构建部分中给出了主类名。当我使用maven命令执行数据流作业然后得到以下错误。

有人可以指导我解决这个问题。

Maven Command

- mvn package 
- java -jar target/sample-1.0.0.jar

错误信息:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/beam/sdk/options/PipelineOptions
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.beam.sdk.options.PipelineOptions

我的管道文件

public interface DefaultOptions extends PipelineOptions,GcpOptions,ApplicationNameOptions,DataflowPipelineDebugOptions,DataflowPipelineWorkerPoolOptions,
BigQueryOptions,GcsOptions,StreamingOptions,CloudDebuggerOptions,DataflowProfilingOptions,PubsubOptions {

我在类文件中的管道初始化

PipelineOptionsFactory.register(DefaultOptions.class);

DefaultOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(DefaultOptions.class);
options.setRunner(DataflowRunner.class);
options.setProject(options.getDataFlowProjectName());
options.setTempLocation(options.getDataFlowProjectTempLocation());
options.setGcpTempLocation(options.getDataFlowProjectTempLocation());
Pipeline p = Pipeline.create(options);

POM文件:

     <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
        <version>2.11.0</version>
     </dependency>

      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>SampleWindowJar</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
google-cloud-dataflow apache-beam
1个回答
0
投票

Cloud Dataflow依赖项不是您需要的唯一依赖项。您还需要与Beam SDK相关的所有依赖项。获得它们的最简单方法是使用Maven原型,Beam提供:

https://beam.apache.org/get-started/quickstart-java/

mvn archetype:generate \
      -DarchetypeGroupId=org.apache.beam \
      -DarchetypeArtifactId=beam-sdks-java-maven-archetypes-starter \
      -DarchetypeVersion=2.11.0 \
      -DgroupId=org.yourorg \
      -DartifactId=my-beam-pipeline \
      -Dversion="0.1" \
      -Dpackage=org.yourorg.pipelines \
      -DinteractiveMode=false

cd my-beam-pipeline

您将看到一个pom.xml文件,以及您可以开发的启动器管道的目录。

一旦创建了原型,它将包含所有基本的SDK依赖项,您也可以添加Dataflow Runner:

<dependency>
   <groupId>org.apache.beam</groupId>
   <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
   <version>2.11.0</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.