BigQuery: java.lang.NoClassDefFoundError: com/google/api/gax/retrying/ExceptionRetryAlgorithm

huangapple go评论108阅读模式
英文:

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 &quot;main&quot; 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.&lt;clinit&gt;(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:

&lt;properties&gt;
    &lt;beam.version&gt;2.19.0&lt;/beam.version&gt;
&lt;/properties&gt;


&lt;dependencies&gt;

    &lt;!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
        &lt;artifactId&gt;commons-collections4&lt;/artifactId&gt;
        &lt;version&gt;4.0&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;com.google.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;google-cloud-bigquery&lt;/artifactId&gt;
        &lt;version&gt;1.110.0&lt;/version&gt;
    &lt;/dependency&gt;


    &lt;!-- Beam --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.beam&lt;/groupId&gt;
        &lt;artifactId&gt;beam-sdks-java-core&lt;/artifactId&gt;
        &lt;version&gt;${beam.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.beam&lt;/groupId&gt;
        &lt;artifactId&gt;beam-sdks-java-io-google-cloud-platform&lt;/artifactId&gt;
        &lt;version&gt;${beam.version}&lt;/version&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;junit&lt;/groupId&gt;
                &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.beam&lt;/groupId&gt;
        &lt;artifactId&gt;beam-sdks-java-extensions-google-cloud-platform-core&lt;/artifactId&gt;
        &lt;version&gt;${beam.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.beam&lt;/groupId&gt;
        &lt;artifactId&gt;beam-runners-google-cloud-dataflow-java&lt;/artifactId&gt;
        &lt;version&gt;${beam.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.beam&lt;/groupId&gt;
        &lt;artifactId&gt;beam-sdks-java-io-jdbc&lt;/artifactId&gt;
        &lt;version&gt;${beam.version}&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

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.

    &lt;dependency&gt;
        &lt;groupId&gt;com.google.api&lt;/groupId&gt;
        &lt;artifactId&gt;gax&lt;/artifactId&gt;
        &lt;version&gt;0.14.0&lt;/version&gt;
    &lt;/dependency&gt;

I hope that adding the above dependency to your pom resolves the issue.

huangapple
  • 本文由 发表于 2020年4月6日 16:57:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/61056188.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定