英文:
BigQuery: java.lang.NoClassDefFoundError: com/google/api/gax/retrying/ExceptionRetryAlgorithm
问题
我正在进行一个Google Dataflow Java项目。我试图在管道的初始化中创建和更新BigQuery表格。所以,为了入门,我正在尝试以以下方式实例化BigQuery Java客户端:
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
在运行时,它给我带来了以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/gax/retrying/ExceptionRetryAlgorithm
at ...
这是我的 pom.xml
文件:
<properties>
<beam.version>2.19.0</beam.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
<version>1.110.0</version>
</dependency>
<!-- Beam -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-extensions-google-cloud-platform-core</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${beam.version}</version>
</dependency>
</dependencies>
我漏掉了什么?
英文:
I'm working on a Google Dataflow Java project. I'm trying to create and update BigQuery tables in the initialisation of the pipeline. So, for getting started, I'm trying to instantiate BigQuery Java Client this way:
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
When running, it brings me the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/gax/retrying/ExceptionRetryAlgorithm
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at com.google.cloud.BaseService.<clinit>(BaseService.java:48)
at com.google.cloud.bigquery.BigQueryOptions$DefaultBigQueryFactory.create(BigQueryOptions.java:46)
at com.google.cloud.bigquery.BigQueryOptions$DefaultBigQueryFactory.create(BigQueryOptions.java:40)
at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:426)
at com.mydomain.Analysis.main(Analysis.java:359)
Caused by: java.lang.ClassNotFoundException: com.google.api.gax.retrying.ExceptionRetryAlgorithm
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 17 more
This is my pom.xml
:
<properties>
<beam.version>2.19.0</beam.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
<version>1.110.0</version>
</dependency>
<!-- Beam -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-extensions-google-cloud-platform-core</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${beam.version}</version>
</dependency>
</dependencies>
What am I missing?
答案1
得分: 2
从错误信息看,似乎缺少包含 com.google.api.gax.retrying.ExceptionRetryAlgorithm.class
的 .jar
文件。
通过快速的谷歌搜索,我找到了将以下依赖项添加到 pom.xml
中的方法。这个 gax.jar
包含了 ExceptionRetryAlgorithm
类。
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>0.14.0</version>
</dependency>
希望将上述依赖项添加到您的 pom 文件中可以解决这个问题。
英文:
From the error it looks like some .jar
containing the com.google.api.gax.retrying.ExceptionRetryAlgorithm.class
is missing.
A quick Google search directed me to add the below dependency to the pom.xml
. This gax.jar
contains the ExceptionRetryAlgorithm
class.
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>0.14.0</version>
</dependency>
I hope that adding the above dependency to your pom resolves the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论