11

このコードを実装したい

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))
    {
        // Get Merchant facade authorization code
        String pairingCode = bitpay.requestClientAuthorization(
            BitPay.FACADE_MERCHANT);

        // Signal the device operator that this client needs to
        // be paired with a merchant account.
        System.out.print("Info: Pair this client with your merchant account using the pairing Code: " + pairingCode);
        throw new BitPayException("Error:client is not authorized for Merchant facade");
    }
}

これらの依存関係を含めました:

<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>

しかし、コードを実行すると、次のようになります。

testGetExchangeRate(com.payment.gateway.bitpay.impl.BitpayImplTest)  Time elapsed: 1.665 sec  <<< ERROR!
java.lang.NoSuchFieldError: INSTANCE
    at com.payment.gateway.bitpay.impl.BitpayImplTest.testGetExchangeRate(BitpayImplTest.java:55)

質問: これを修正する方法についてアドバイスをいただけますか?

4

1 に答える 1

1

githubpom.xml上のライブラリ プロジェクトのファイルの maven 依存関係を見ると、同じアーティファクト バージョンではありませんが、次のいくつかのライブラリに依存していることがわかります。java-bitpay-clientorg.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>

そのうち:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.3</version>
</dependency>

依存関係には代わりにhttpcoreversionがあるため、コメントとリンクされた同様の質問でジェイコブが指摘したように、4.4.5明らかに依存関係の競合があります。

Maven 依存関係仲介メカニズムを介して、ビルドは最新の version を4.4.5取得します。これは、依存関係の間で明示的に宣言されているためです。したがって、実行時java-bitpay-clientに依存関係の 1 つの異なるバージョンがクラスパスに含まれ、最終的な例外が発生する可能性があります。

考えられる解決策は、httpcore依存関係をあなたから削除し、dependencies推移的な依存関係を介してクラスパスに入るようにすることです(バージョン4.3は次に入る必要があります)。

プロジェクトのコンソールから実行して、上記の説明を確認することもできます。

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

他の推移的な依存関係の中で、 も取得する必要がありhttpcoreます。


補足: typevalue を持つ依存関係を定義したようですjarjarが依存関係のデフォルト値であることは省略できtypeます。つまり、依存関係はデフォルトで jar ファイルです。公式ポンリファレンスから:

type: 依存アーティファクトのpackagingタイプに対応します。デフォルトはjarです。

于 2016-09-10T21:37:46.830 に答える