gpt4 book ai didi

java - Google Dataflow 作业在 eclipse 上运行时工作正常,但当我使用 mvn 编译它并使用 java -cp 命令运行文件时出现错误

转载 作者:行者123 更新时间:2023-12-02 11:19:47 25 4
gpt4 key购买 nike

我正在从 Dataflow sdk 1.x 迁移到使用 apache beam 的 2.x。当我使用作为 java 应用程序运行在 eclipse 上运行代码时,代码运行正常。但是当我使用mvn cleancompile assembly:single 然后使用命令java -cp运行类文件我收到这些日志,然后出现异常

INFO: PipelineOptions.filesToStage was not specified. Defaulting to files 
from the classpath: will stage 1 files. Enable logging at DEBUG level to see
which files will be staged.
Apr 25, 2018 11:17:01 AM com.example.LogParser parse
INFO: Currently processing file: File1.gz
Exception in thread "main" java.lang.NoSuchMethodError:
com.google.common.base.Preconditions.checkArgument(ZLjava/lang/
String;Ljava/lang/Object;Ljava/lang/Object;)V at
org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:1512)
at org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$Write.expand(BigQueryIO.java:1041)
at org.apache.beam.sdk.Pipeline.applyInternal(Pipeline.java:537)
at org.apache.beam.sdk.Pipeline.applyTransform(Pipeline.java:472)
at org.apache.beam.sdk.values.PCollection.apply(PCollection.java:286)
at com.example.LogParser.parse(LogParser.java:541)
at
com.example.LogParser.main(LogParser.java:167)

我尝试更新 Guava 版本,但没有帮助。

我还注意到,当我使用 eclipse 运行我的类文件时,我得到的日志与使用 jar 文件运行它时不同

INFO: PipelineOptions.filesToStage was not specified. Defaulting to files 
from the classpath: will stage 147 files. Enable logging at DEBUG level to
see which files will be staged.

最佳答案

我能够通过添加这些maven依赖项而不是maven-assemble-plugin,然后使用mvn package而不是mvn assembly来解决该错误

      <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<parallel>all</parallel>
<threadCount>4</threadCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${maven-surefire-plugin.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-bundled-${project.version}</finalName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/LICENSE</exclude>
<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.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

关于java - Google Dataflow 作业在 eclipse 上运行时工作正常,但当我使用 mvn 编译它并使用 java -cp 命令运行文件时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50018817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com