java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory - google-bigquery

I want to create a web application running on Tomcat 7.0 with JRE JavaSE-1.6 on osx 10.8.
I am using a tutorial from the developers site and the error occurs when I try to call
clientSecrets = GoogleClientSecrets.load(new JacksonFactory(), reader);
I added the Jar google-http-client-jackson-1.16.0-rc.jar to my build path and still get following error:
java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
My classpath specifically points to this Jar too.

I just fixed this by changing the following lines:
Original: import com.google.api.client.json.jackson.JacksonFactory;
Modified: import com.google.api.client.json.jackson2.JacksonFactory;

I had a similar problem and solved it by manually adding the required JAR's to my WEB-INF\lib folder outside Eclipse.

From this page here, it says you need 3 libraries:
1) The Generated Java client library for BigQuery
2) The Google HTTP Client Library for Java
3) The Google OAuth Client Library for Java
Do you have them all? It sounds like you have #2, but it sounds like you're missing the google HTTP client.

In POM add below dependency-
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-gson</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.34.1</version>
</dependency>
Note: In above dependency version can be changed
2.Import statement
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
Usage
private static final JsonFactory JSON_FACTORY =
GsonFactory.getDefaultInstance();
GoogleClientSecrets clientSecrets =GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(in));

Related

java.lang.NoSuchFieldError: Companion when using okhttp3 and selenium

I'm using Retrofit2 and Okhttp to make HTTP calls in my project, that also uses Selenium. As soon as I added the following dependency:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.9.0</version>
</dependency>
I started to see the following error:
java.lang.NoSuchFieldError: Companion
at okhttp3.logging.HttpLoggingInterceptor$Logger$Companion$DefaultLogger.log(HttpLoggingInterceptor.kt:116)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:168)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
I have checked some related issues and everything points to a dependency problem. However, I'm using the latest versions for Okhttp and Retrofit2 (2.9.0), as well as for selenium-java:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
What I'm trying to do is just to log a simple request using:
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(url)
.client(httpClient.build())
.build();
Do you know what could be the issue?
I'm using the latest Kotlin plugin in IntelliJ
It's most likely a dependency problem. See which JARs are imported in your IDE then debug the error. Otherwise make a simple standalone android project to run this code. You can also use the okhttp bom to upgrade cleanly to 4.9.0.
https://github.com/square/okhttp#releases
dependencies {
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
}

Got following error when try to execute first script to open web url with help of gecko driver -

Code is as below:
package nw;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.24.0-win64.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.shop.demoqa.com");
}
}
Hello i am facing this issue in selenium while launching the above given program --
program..plz help me
com/google/common/collect/ImmutableMap
at org.openqa.selenium.firefox.FirefoxDriver.<clinit>(FirefoxDriver.java:108)
at nw.test.main(test.java:14)
Caused by: java.lang.ClassNotFoundException:
com.google.common.collect.ImmutableMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
You have not added selenium-server.jar in your build or dependency in your POM.
You have added selenium-java.jar in your build or as dependency due to which your code is compiling fine
You need to add that too
Download jar from below location:
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server
OR add below dependency
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>
Note that here I am using version 3.141.59 for server so your selenium java jar should of same version to prevent from any unrelated error
Selenium relies on Google Guava and your test is failing to find ImmutableMap class.
The solution is to add the relevant version of guava to your project classpath.
The full set of dependencies would be:
animal-sniffer-annotations-1.14.jar
byte-buddy-1.8.15.jar
checker-compat-qual-2.0.0.jar
commons-exec-1.3.jar
error_prone_annotations-2.1.3.jar
guava-25.0-jre.jar
j2objc-annotations-1.1.jar
jsr305-1.3.9.jar
okhttp-3.11.0.jar
okio-1.14.0.jar
selenium-api-3.141.59.jar
selenium-chrome-driver-3.141.59.jar
selenium-edge-driver-3.141.59.jar
selenium-firefox-driver-3.141.59.jar
selenium-ie-driver-3.141.59.jar
selenium-java-3.141.59.jar
selenium-opera-driver-3.141.59.jar
selenium-remote-driver-3.141.59.jar
selenium-safari-driver-3.141.59.jar
selenium-support-3.141.59.jar
Going forward I would recommend using a dependency management solution like Maven or Gradle so you won't have to manually download the .jars. Check out Selenium with Java article for comprehensive explanation and example code snippets.

OkHttp: NoSuchMethodError copyInto in TlsUtil

Running instrumentation tests with RESTMock we are getting this error
java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
FATAL EXCEPTION: pool-6-thread-1
Process: com.example.debug, PID: 6606
java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
at okhttp3.tls.internal.TlsUtil.newKeyManager(TlsUtil.kt:84)
at okhttp3.tls.HandshakeCertificates$Builder.build(HandshakeCertificates.kt:144)
at io.appflate.restmock.SslUtils.localhost(SslUtils.java:49)
at io.appflate.restmock.RESTMockServer.setUpHttps(RESTMockServer.java:91)
at io.appflate.restmock.RESTMockServer.init(RESTMockServer.java:74)
at io.appflate.restmock.RESTMockServerStarter$1.run(RESTMockServerStarter.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
This is the line in question in OkHttp
IIUC, Kotlin can treat a varargs as a Kotlin Array and then call extensions functions like copyInto
We're on OkHttp 4.0.1, Kotlin 1.3.40, R8 1.5.41
Our test apk correctly contains copyInto method so I don't think it's a proguard/R8 issue:
I'm at a loss as to what to test next. I asked on OkHttp's github issuse page and they suggested I post here link
Update: still happening on OkHttp 4.1.0. Also I realized that it can't be an R8 issue since R8 doesn't remove code from test apk.
I had a same issue , then added the mentioning lib to my project. It solved my problem:
maven :
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.70</version>
</dependency>
or
'org.jetbrains.kotlin:kotlin-stdlib:1.3.70'
I got the same issue when I was using okhttp3.mockwebserver.MockWebServer with https enabled with a server certificate from okhttp-tls.
In my case, the problem was that by just importing the com.squareup.okhttp3:okhttp-tls:4.2.0 dependency, org.jetbrains.kotlin:kotlin-stdlib was being resolved to version 1.2.71.
Given the copyInto method was introduced starting kotlin 1.3 it was failing with the same error you have.
I fixed it by adding explicitly the kotlin version in my gradle.build file:
testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'
I got the same issue, but I'm developing a multi-module java project. It was useful that add a dependency for kotlin-stdlib in pom.xml that belongs to this module while unit testing...
When I boot this whole project, this issue came out agnain. Finally, I find this dependency need to be in the whole project's pom.xml, I mean the pom.xml in the project's root dir.

IntelliJ Idea groovy.lang.GroovyRuntimeException: Conflicting module versions

My maven builds are fine and able to run groovy from cli. However if I try to run my groovy class inside IntelliJ Idea (version 15 community edition), its gives me below error.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:61)
at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
at groovy.lang.Closure.<init>(Closure.java:219)
at groovy.lang.Closure.<init>(Closure.java:236)
at groovy.lang.Closure$1.<init>(Closure.java:203)
at groovy.lang.Closure.<clinit>(Closure.java:203)
at filter.App.<clinit>(App.groovy)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.3.9 and you are trying to load version 2.4.5
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:509)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:77)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:71)
at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:53)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:71)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:33)
... 10 more
Not sure how to get rid of this.
This is my pom dependency.
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.5</version>
</dependency>
And I am using spring boot.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath></relativePath>
</parent>
This is my groovy version installed in system.
Groovy Version: 2.4.5 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Linux
Please let me know if someone knows about this.
you have to delete groovy lib from project settings.
shift+alt+ctrl + s, global libraries - delete groovy. And when trying to run applictaion / test you should have point to groovy from maven dependencies.
#SuperAndrew's suggestion wasn't my situation -- I didn't have Groovy registered under Global Libraries under my Project Structure. But I did find this StackExchange solution resolved my issue. Add this code to your build.gradle file.
configurations.all {
resolutionStrategy {
force 'org.codehaus.groovy:groovy-all:2.4.4'
}
}
I was seeing this in a recent project after I upgraded Gradle to 7.+
The reason this was causing a problem for me was that Gradle 7.+ is now using Groovy 3.+ and as such various other plugins needed to be upgraded (e.g. spock-core).
It was this incompatibility of various dependencies that were causing this and once I updated all of them this issue went away.

Plugin works on Jira 5.2.10, but does not on 6.0

Made plugin for Jira with data exchange via servlet (using FileUploadServlet).
Testing on Jira 5.2.10 was OK, but on 6.0 there is a trouble:
2013-06-27 21:46:26,575 http-bio-8080-exec-24 ERROR anri 1306x1054x1 4bhuqg 169.254.57.250 /plugins/servlet/smartActDataServlet [atlassian.plugin.module.PrefixDelegatingModuleFactory] Detected an error (NoClassDefFoundError) instantiating the module for plugin 'com.polontech.jira.plugin.activity.smartact.SmartAct' for module 'dataServlet': org/apache/commons/fileupload/FileUploadException. This error is usually caused by your plugin using a imported component class that itself relies on other packages in the product. You can probably fix this by adding the missing class's package to your instructions; for more details on how to fix this, see https://developer.atlassian.com/display/DOCS/NoClassDefFoundError .
2013-06-27 21:46:26,577 http-bio-8080-exec-24 ERROR anri 1306x1054x1 4bhuqg 169.254.57.250 /plugins/servlet/smartActDataServlet [atlassian.plugin.servlet.DefaultServletModuleManager] Unable to create servlet
com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
Why? What's the difference between 5.2.10 and 6.0? How to solve the problem?
As I get, problem is with FileUpload. Maybe, there is a way to add this to my project?
dependencies are on their place:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
Error seems very vague. We cannot know what the difference is but as with every software product things change between versions and stuff works, breaks or is deprecated.
Go to the Atlassian Support and Answers sites and get the answer you're looking for from the guys that develop JIRA.They'll know how to help.
Also review all the information on https://developer.atlassian.com/display/JIRADEV/Preparing+for+JIRA+6.0
since 6.0 is a major release
Problem solved. Just check the version of all dependencies: I had to use common-fileupload-1.2.2:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>