maven - java.lang.NoSuchFieldError: INSTANCE in bitpay SDK -


i want implement this code

public void testgetexchangerate() throws exception {     eckey key = keyutils.createeckey();      string clientname = "server 1";     bitpay bitpay = new bitpay(key, clientname);      if (!bitpay.clientisauthorized(bitpay.facade_merchant))     {         // merchant facade authorization code         string pairingcode = bitpay.requestclientauthorization(             bitpay.facade_merchant);          // signal device operator client needs         // paired merchant account.         system.out.print("info: pair client merchant account using pairing code: " + pairingcode);         throw new bitpayexception("error:client not authorized merchant facade");     } } 

i included these dependencies:

<dependency>     <groupid>com.github.bitpay</groupid>     <artifactid>java-bitpay-client</artifactid>     <version>v2.0.4</version> </dependency> <dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpcore</artifactid>     <version>4.4.5</version>     <type>jar</type> </dependency> 

but when run code get:

testgetexchangerate(com.payment.gateway.bitpay.impl.bitpayimpltest)  time elapsed: 1.665 sec  <<< error! java.lang.nosuchfielderror: instance     @ com.payment.gateway.bitpay.impl.bitpayimpltest.testgetexchangerate(bitpayimpltest.java:55) 

question: can give advice how can fix this?

looking @ maven dependencies of pom.xml file of library project on github, although not same artifact version, can see java-bitpay-client depends on several libraries org.apache.httpcomponents:

<dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>fluent-hc</artifactid>     <version>4.3.1</version> </dependency> <dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpclient</artifactid>     <version>4.3.1</version> </dependency> <dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpclient-cache</artifactid>     <version>4.3.1</version> </dependency> <dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpcore</artifactid>     <version>4.3</version> </dependency> <dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpmime</artifactid>     <version>4.3.1</version> </dependency> 

among which:

<dependency>     <groupid>org.apache.httpcomponents</groupid>     <artifactid>httpcore</artifactid>     <version>4.3</version> </dependency> 

in dependencies instead have httpcore version 4.4.5, hence there dependency conflict, pointed out jacob in comments , linked similar question.

via maven dependency mediation mechanism, build pick latest, version 4.4.5, because explicitely declared among dependencies, hence @ runtime java-bitpay-client have in classpath different version of 1 of dependencies, may cause final exception.

a possible solution remove httpcore dependency dependencies , let come classpath via transitive dependencies (version 4.3 should into).

you can confirm description above running console on project:

mvn dependency:tree -dincludes=com.github.bitpay 

you should get, among other transitive dependencies, httpcore.


side note: see defined dependency type having value jar. can omit that, jar default value dependency type, is, dependencies default jar files. official pom reference:

type: corresponds dependant artifact's packaging type. defaults jar.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -