For creating a REST Client am using the below dependency in Spring Boot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
Which in turn downloads the jersey-client-2.23.1.jar.
My code for request builder is as below:
Client client = ClientBuilder.newClient();
WebTarget targetUrl = client.target("Some URL").path(userid)
.path("Some String");
Builder requestBuilder = targetUrl.request(MediaType.APPLICATION_JSON);
JsonParser parser = new JsonParser();
JsonArray objArray = (JsonArray) parser.parse(requestBuilder.get(String.class));
However I am getting the below exception in line number 3 of the above code:
java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V
at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:336) ~[jersey-client-2.23.1.jar:na]
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:221) ~[jersey-client-2.23.1.jar:na]
at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:59) ~[jersey-client-2.23.1.jar:na]
I saw few solution that it is due to version mismatch. So, I tried to added a lower version dependency:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.2</version>
</dependency>
But spring boot is not considering this version of jersey-client. Is there any way out so that I can solve the issue?
EDIT 1:
As mentioned in the first answer I used mvn dependency:tree and found 2 different version of jersey client available. One is compile time and one is run time:
[INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:1.4.0.RELEASE:compile
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:2.23.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-common:jar:2.23.1:compile
[INFO] | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.23.1:compile
[INFO] | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:2.23.1:compile
and
[INFO] +- some.project.specific:jar:1.1.5.RELEASE:compile
[INFO] | +- some.project.specific:jar:1.4.10:compile
[INFO] | | +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
I tried to exclude version 2.23.1 as below. Still it is including the jar.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client-2.23.1</artifactId>
</exclusion>
</exclusions>
</dependency>
Check other dependencies on your project, try running mvn dependency:tree. Probably you have some other dependency to jersey 1.XX version, you should exclude it to keep just the 2.23.1.
Related
I'm using Springboot 2.3.0.RELEASE
I wanted to upgrade just the tomcat version from 9.0.35 to 9.0.37 for which I tried the below steps and nothing worked :
Tried upgrading only the spring-boot-starter-tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
But even after that change, I get to see this in my dependency tree :
+- org.springframework.boot:spring-boot-starter-tomcat:jar:2.3.3.RELEASE:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.35:compile
[INFO] | +- org.glassfish:jakarta.el:jar:3.0.3:compile
[INFO] | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.35:compile
I tried adding this property in POM, but that too didn't work:
<tomcat.version>9.0.37</tomcat.version>
We are pointing to Elasticsearch 5.6.4. I used below entry in pom.xml:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.6.4</version>
</dependency>
When I created the dependency tree:
[INFO] +- org.elasticsearch.client:transport:jar:5.6.4:compile
[INFO] | +- org.elasticsearch:elasticsearch:jar:2.4.4:compile (version
managed from 5.6.4)
[INFO] | | +- org.apache.lucene:lucene-core:jar:5.5.2:compile
[INFO] | | +- org.apache.lucene:lucene-backward-codecs:jar:5.5.2:compile
Can someone help to resolve this. I need elasticsearch-5.6.4.jar, but I am getting run time issues.
<pre>
this resolved my issue
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.6.4</version>
</dependency>
</dependencies>
</dependencyManagement>
</pre>
I'm using
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.1.0.Final</version>
</dependency>
in a apache-tomcat-8.0.41 web service.
In this link they say "Hibernate EntityManager implements the programming interfaces and lifecycle rules as defined by the JPA 2.0 specification"
https://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html_single/
But it's for the 3.6 version.
It's the same for 5.1 ?
hibernate-jpamodelgen is neither JPA nor hibernate. It is a maven plugin which helps to use JPA by auto-generating classes.
For example, if you have a class named User, hibernate-jpamodelgen will create a class User_ that contains fields which are very useful when using the criteria API.
For your JPA version, you should look at another dependency. If you have this one, then you are using JPA > 2.0
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
I suggest you read the docs of the version you are using. As for hibernate and JPA compatibility see here: Hibernate releases
Hibernate 5.1 docs: Hibernate 5.1 docs
Another simple way to discover what version you are using is to execute the maven command:
mvn dependency:tree
Here I can see I'm running JPA 2.2.3:
> mvn depedency:tree
...
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.7.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:2.7.2:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.7:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.7.2:compile
[INFO] | | \- com.zaxxer:HikariCP:jar:4.0.3:compile
[INFO] | +- jakarta.transaction:jakarta.transaction-api:jar:1.3.3:compile
[INFO] | +- jakarta.persistence:jakarta.persistence-api:jar:2.2.3:compile <!-- JPA
[INFO] | +- org.hibernate:hibernate-core:jar:5.6.10.Final:compile
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.12.12:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | +- org.jboss:jandex:jar:2.4.2.Final:compile
[INFO] | | \- org.hibernate.common:hibernate-commons-annotations:jar:5.1.2.Final:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.7.2:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:2.7.2:compile
[INFO] | | \- org.springframework:spring-orm:jar:5.3.22:compile
[INFO] | \- org.springframework:spring-aspects:jar:5.3.22:compile
...
I use geckodriver v0.15.0 (Latest release) and Firefox 52.0.1 (64 bits)
Here is my code :
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
Here is the dependencies for Selenium in my pom (latest version of Selenium) :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
And the exception at runtime :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.net.PortProber.waitForPortUp(IILjava/util/concurrent/TimeUnit;)V
at org.openqa.selenium.firefox.GeckoDriverService.waitUntilAvailable(GeckoDriverService.java:73)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
If I add this dependency :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.3.1</version>
</dependency>
I have got another exception :
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/Interactive
What dependency is missing? Thank you.
UPDATE
mvn dependency:tree with htmlunit-driver 2.25, selenium-remote-driver 3.3.1, selenium-firefox-driver 3.3.1, selenium-support 3.3.1
[INFO] +- org.seleniumhq.selenium:htmlunit-driver:jar:2.25:compile
[INFO] | +- org.seleniumhq.selenium:selenium-api:jar:2.53.1:compile
[INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.21:compile
[INFO] | +- xalan:xalan:jar:2.7.2:compile
[INFO] | | \- xalan:serializer:jar:2.7.2:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.5.2:compile
[INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.17:compile
[INFO] | +- net.sourceforge.htmlunit:neko-htmlunit:jar:2.21:compile
[INFO] | | \- xerces:xercesImpl:jar:2.11.0:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.18:compile
[INFO] | | \- org.w3c.css:sac:jar:1.3:compile
[INFO] | +- commons-io:commons-io:jar:2.4:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-client:jar:9.4.1.v20170120:compile
[INFO] | +- org.eclipse.jetty:jetty-util:jar:9.4.1.v20170120:compile
[INFO] | +- org.eclipse.jetty:jetty-io:jar:9.4.1.v20170120:compile
[INFO] | +- org.eclipse.jetty:jetty-client:jar:9.4.1.v20170120:compile
[INFO] | | \- org.eclipse.jetty:jetty-http:jar:9.4.1.v20170120:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-common:jar:9.4.1.v20170120:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-api:jar:9.4.1.v20170120:compile
[INFO] +- org.seleniumhq.selenium:selenium-remote-driver:jar:3.3.1:compile
[INFO] | +- cglib:cglib-nodep:jar:3.2.4:compile
[INFO] | +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] | \- net.java.dev.jna:jna-platform:jar:4.1.0:compile
[INFO] | \- net.java.dev.jna:jna:jar:4.2.2:compile
[INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:3.3.1:compile
[INFO] \- org.seleniumhq.selenium:selenium-support:jar:3.3.1:compile
Update 2
OS: Linux 64 bits
Here is the required dependencies (I cleaned the .m2 directory too) :
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
Maybe you have jar versions conflict error. When I had that bug in my application, I found that it was referring the old Selenium jar. To resolve this, I removed the old jar's and rebuild the project with Selenium 3 jars.
Ensure that you have right libraries added to your project.
the command mvn dependency:tree can help you with this.
Note: when you use the test scope it's mean the the dependency is only available for the test compilation and execution phases, So you must put your code in a Test method or remove the scope tag
Hope this helps.
check if you have the selenium-java dependency of the same version as your other dependencies
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
Add System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\geckodriver.exe"); to your code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CheckFireFox {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>StackOverFlow</groupId>
<artifactId>StackOverFlow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
Console output :
Mar 27, 2017 2:39:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Page title is: Google
Update the selenium version
Download the geckodriver and set system path eg "F:\geckodriver-v0.20.1-win64"
Add following code snippet to your existing code
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Now run the script and it will work for you, hope this helps.
Overall applicatiom I'm using Apache HttpComponents dependency:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
But also another library uses this artifact, but different version (4.3.2, not 4.5.2):
<dependency>
<groupId>com.sendgrid</groupId>
<artifactId>sendgrid-java</artifactId>
</dependency>
The problem is that API between this versions is changed and I'm getting this error:
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
How I can say to maven not to override Sendgrid's version of HttpComponents (4.3.2) with 4.5.2?
EDIT: version of httpcomponents is specified in dependencyManagement section of parent pom
Given the following parent pom.xml section:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sendgrid</groupId>
<artifactId>sendgrid-java</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<modules>
<module>module-a</module>
<module>module-b</module>
</modules>
Indeed in module-a the dependency tree is the following, executing:
mvn dependency:tree
We get as part of the output:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # module-a ---
[INFO] com.sample:module-a:jar:0.0.1-SNAPSHOT
[INFO] \- com.sendgrid:sendgrid-java:jar:2.0.0:compile
[INFO] +- org.json:json:jar:20140107:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- com.sendgrid:smtpapi-java:jar:1.0.0:compile
[INFO] \- org.apache.httpcomponents:httpmime:jar:4.3.4:compile
Note:
We get org.apache.httpcomponents:httpclient:jar:4.5.2:compile
We also get org.apache.httpcomponents:httpcore:jar:4.3.2:compile
A potential versons mismatch happens here between libraries of the same family
Adding then to the module-a's pom.xml the following:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
</dependencies>
</dependencyManagement>
And re-running our dependency tree execution, we get as part of the output:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # module-a ---
[INFO] com.sample:module-a:jar:0.0.1-SNAPSHOT
[INFO] \- com.sendgrid:sendgrid-java:jar:2.0.0:compile
[INFO] +- org.json:json:jar:20140107:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.2:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- com.sendgrid:smtpapi-java:jar:1.0.0:compile
[INFO] \- org.apache.httpcomponents:httpmime:jar:4.3.4:compile
We now get httpcore and httpclient aligned, with the versions we wanted.
Also note the httpmime to version 4.3.4, it's a fix version change, but still a misalignment (should be harmless though).
In this case it seems you are adding governance at parent level in dependencyManagement (good approach), but then at the level of one of the modules you need to override it. That can happen, but better to properly comment it, for maintenance and for the future yourself looking at it in the future.
Also note: other modules in this project would not be affected by this change, that is, they will still get version 4.5.2. If the final result of the whole multimodule build is an ear or war file, for example, carefully check what you eventually get.
It is impossible in a simple maven project to have 2 different versions of the same artifact in the classpath. So you cannot have 4.3.2 and 4.5.2 versions in the classpath simultaneously.
However there are several options... You can either
use in your project the older version (4.3.*), compatible with sendgrid-java dependency (simplest way); or
update sendgrid-java dependency, if newer one is compatible with http components 4.5.* (preferred way); or
mark sendgrid-java as a 'provided' dependency, build a separate class loader in runtime and load it with correct dependencies versions (a bit tricky, but I saw this approach in a couple bank applications)