1

I created this simple class:

import javax.swing.JOptionPane;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class TweetSent {

    public static void main(String[] args) {
        try {
            HttpResponse<JsonNode> request = Unirest.get("https://intridea-tweetsentiments.p.mashape.com/twitsentiment/?num_tweets=10&query=%3Cquery%3E").basicAuth("X-Mashape-Authorization", "#######################").asJson();
            JOptionPane.showMessageDialog(null,"request: "+request);
        } catch (UnirestException e) {
            JOptionPane.showMessageDialog(null,"ERROR: "+e);
            e.printStackTrace();
        }
    }

}

But I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at com.mashape.unirest.request.HttpRequest.basicAuth(HttpRequest.java:61)
    at com.NR.V.TweetSent.main(TweetSent.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64

EDIT:

I removed all of the <repository> elements mentioned in the pom.xml file:

<dependency>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    <version>4.0-beta4</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.3</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>

I get this from Maven:

[WARNING] The POM for com.mashape.unirest:unirest-java:jar:1.3.0-SNAPSHOT is missing, no dependency information available

enter image description here

ManInMoon
  • 6,795
  • 15
  • 70
  • 133

2 Answers2

2

I'm the author of Unirest-Java.

Can you please update Unirest to its latest version? This problem should have been fixed with version 1.3.0.

Also make sure to have imported all the required dependencies. You can read the installation instructions at https://github.com/Mashape/unirest-java#installing

Edit: To force Maven to re-download the library, try deleting the unirest-java folder at ~/.m2/repository/com/mashape/unirest/unirest-java/ and execute mvn clean compile again.

Mark
  • 67,098
  • 47
  • 117
  • 162
  • Maven says it can't find artifact 1.3.0-SNAPSHOT, but it can find 1.2.8 – ManInMoon Nov 03 '13 at 08:47
  • Unirest now uses Maven Central. Try to remove the entry. As you can see, it has been properly uploaded: https://oss.sonatype.org/content/repositories/snapshots/com/mashape/unirest/unirest-java/1.3.0-SNAPSHOT/ – Mark Nov 04 '13 at 02:50
  • Still no luck. Please see EDIT 2 in question. – ManInMoon Nov 04 '13 at 09:03
  • This works for me: delete the "unirest-java" folder at "~/.m2/repository/com/mashape/unirest/unirest-java/" and execute "mvn clean compile" again. It should re-download the library from Maven Central. Answer updated. – Mark Nov 04 '13 at 23:59
  • And please update the version from `1.3.0-SNAPSHOT` to `1.3.0` – Mark Nov 05 '13 at 03:15
  • Please look at picture of folder structure above. I deleted mashape as you suggested, but when it was regenerated "SNAPSHOT" version appears. But still I get Maven cannot find it! – ManInMoon Nov 05 '13 at 09:07
  • This is very weird, the SNAPSHOT shouldn't be downloaded if the version is set to "1.3.0". The following pom.xml file works for me: https://gist.github.com/thefosk/7325187 I've also tried it on fresh installations, and it works. Try to download it and execute "mvn clean compile" to see if it works (delete the Unirest folder again in your local repository). – Mark Nov 05 '13 at 20:05
0

It's advisable to package everything in one uber jar by using Maven.

Please refer to this post on how to use Unirest in your Java projects.

Chris Ismael
  • 612
  • 5
  • 13
  • 14