TAS
TAS

Reputation: 103

java btc trade application compile time errors (HTTP Components)

I'm working on a simple java application in eclipse that will make a trade for me on btc-e.com. I just wrote a trade method that is getting a bunch of compile-time errors. I'm using Apache httpcore and httpclient. I can't seem to figure out how why it isn't working. I would really appreciate any help; I'm really confused at this point. These are the JAR files that i'm including in the buildpath:

This is the code:

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;



public class Trade {


public static void buy(double rate, double amount) throws ClientProtocolException, IOException{

    Calendar now = Calendar.getInstance();
    long nonce = ( now.getTimeInMillis()/1000);
    String api_key= "00000000-00000000-00000000-00000000-00000000";
    String api_secret = "---------------------------------------";


    //Create a new HttpClient and Post Header
    HttpClient client = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://btc-e.com/tapi");

     // Add data
    HashMap params = new HashMap();
    params.put("method", "Trade");
    params.put("pair", "btc_usd");
    params.put("type", "buy");
    params.put("rate", rate);
    params.put("amount", amount);
    params.put("nonce", nonce);


    HashMap headers = new HashMap();
    headers.put("Contnent-type", "x-www-form-urlencoded");
    headers.put("key", api_key);
    headers.put("sign", api_secret);

    try {
        httppost.setEntity(new UrlEncodedFormEntity((List<NameValuePair>) params));
        // Execute HTTP Post Request
        HttpResponse response = client.execute(httppost);





    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }







}

And here are the compile time errors:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.impl.client.CloseableHttpClient.(CloseableHttpClient.java:58) at org.apache.http.impl.client.AbstractHttpClient.(AbstractHttpClient.java:287) at org.apache.http.impl.client.DefaultHttpClient.(DefaultHttpClient.java:147) at Trade.buy(Trade.java:31) at Main.main(Main.java:10) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 5 more

Upvotes: 0

Views: 63

Answers (1)

hugh
hugh

Reputation: 2280

You'll also want to include Apache Commons Logging, looks like this is a transitive dependency of httpclient.

Longer term, you might want to look into using a dependency management tool (like Maven!) which will handle this sort of thing for you - as well as handling this kind of dependency issue, it will make your build more stable and repeatable, without all the manual adding of JARs.

Upvotes: 0

Related Questions