When connecting java to Google Big Query I get Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory

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

When connecting java to Google Big Query I get Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory

问题

我有一个Java程序,想用它来对Google BigQuery运行查询。

在启动程序时,我遇到了以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
    at com.simba.googlebigquery.googlebigquery.core.BQConnection.connect(Unknown Source)
    at com.simba.googlebigquery.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.googlebigquery.jdbc.common.AbstractDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at missioncontrol.main(missioncontrol.java:60)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

我已经下载了Simba gbq jdbc驱动程序,并进行了授权设置。我的连接字符串如下:

jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=redacted;OAuthType=0;OAuthServiceAcctEmail=redacted@redacted.iam.gserviceaccount.com;OAuthPvtKeyPath=/home/redacted/redacted.p12;

我的CLASSPATH最初是这样的:

/opt/google/GoogleBigQueryJDBC42.jar

但我为了解决这个问题添加了一堆jar文件,现在它看起来像这样:

/google-http-client-1.29.0.jar:/opt/google/google-http-client-jackson2-1.28.0.jar:/opt/google/jackson-annotations-2.9.0.jar:/opt/google/jackson-core-2.9.8.jar:/opt/google/jackson-databind-2.9.8.jar:/opt/google/GoogleBigQueryJDBC42.jar

这是我的环境信息:

$uname -a
Linux ip-172-31-59-210.ec2.internal 4.14.123-111.109.amzn2.x86_64 #1 SMP Mon Jun 10 19:37:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$java -version
openjdk version "1.8.0_222-ea"
OpenJDK Runtime Environment (build 1.8.0_222-ea-b03)
OpenJDK 64-Bit Server VM (build 25.222-b03, mixed mode)

有关我漏掉了什么的想法吗?

谢谢,
Mary

英文:

I have a Java program that I want to use to run queries against google big query.

I am getting this error when starting my program:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
    at com.simba.googlebigquery.googlebigquery.core.BQConnection.connect(Unknown Source)
    at com.simba.googlebigquery.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.googlebigquery.jdbc.common.AbstractDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at missioncontrol.main(missioncontrol.java:60)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

I have downloaded the Simba gbq jdbc driver. I have set up my authorizations. My connection string looks like this:

jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=redacted;OAuthType=0;OAuthServiceAcctEmail=;redaacted@redacted.iam.gserviceaccount.com;OAuthPvtKeyPath=/home/redacted/redacted/redacted.p12;

My CLASSPATH Originally looked like this:
/opt/google/GoogleBigQueryJDBC42.jar

But I've added a bunch of jar files in an effort to solve this problem, so now it looks like this:

/google-http-client-1.29.0.jar:/opt/google/google-http-client-jackson2-1.28.0.jar:/opt/google/jackson-annotations-2.9.0.jar:/opt/google/jackson-core-2.9.8.jar:/opt/google/jackson-databind-2.9.8.jar:/opt/google/GoogleBigQueryJDBC42.jar

This is my environment:

$uname -a
Linux ip-172-31-59-210.ec2.internal 4.14.123-111.109.amzn2.x86_64 #1 SMP Mon Jun 10 19:37:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$java -version
openjdk version "1.8.0_222-ea"
OpenJDK Runtime Environment (build 1.8.0_222-ea-b03)
OpenJDK 64-Bit Server VM (build 25.222-b03, mixed mode)

Any thoughts on what I am missing?

Thanks,
Mary

答案1

得分: 1

错误可能是因为未在类路径中包含JsonFactory.jar的父类。请尝试使用'/opt/google/*'代替逐个列出类路径中的每个.jar文件。

英文:

The error is likely because the parent class of JsonFactory.jar is not included in your classpath. Instead of listing every .jar individually in your classpath, try using '/opt/google/*' instead.

huangapple
  • 本文由 发表于 2020年5月30日 00:17:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/62090349.html
匿名

发表评论

匿名网友

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

确定