user2696955
user2696955

Reputation: 33

java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory getting this error even after adding the desired imports

here is my code. I've added all the dependencies then also getting such error. google-http-client-jackson2-1.17.0-rc.jar

here in this code in getting above mentioned error at JsonFactory jsonFactory = new JacksonFactory();

import com.google.api.services.customsearch.Customsearch;
import com.google.api.services.customsearch.model.Search;
import com.google.api.services.customsearch.model.Result;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;

protected SearchResult[] doSearch() {


    HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer()
    {   
        @Override
        public void initialize(HttpRequest request) throws IOException {
        }
    };


    JsonFactory jsonFactory = new JacksonFactory();
    Customsearch csearch = new Customsearch( new  NetHttpTransport(),  jsonFactory,  httpRequestInitializer);
    Customsearch.Cse.List listReqst;


    try {
            listReqst = csearch.cse().list(query.getQueryString());
            listReqst.setKey(GOOGLE_KEY);
            // set the search engine ID got from API console
            listReqst.setCx("search engine ID"); 
            // set the query string
            listReqst.setQ(query.getQueryString());
            // language chosen is English for search results 
            listReqst.setLr("lang_en"); 
            // set hit position of first search result
            listReqst.setStart((long) firstResult);
            // set max number of search results to return
            listReqst.setNum((long) maxResults);
            //performs search
            Search result = listReqst.execute();
            java.util.List<Result> results =  result.getItems();
            String urls[] = new String [result.size()];
            String snippets[] = new String [result.size()];
            int i=0;
            for (Result r : results){
                urls[i] = r.getLink();
                snippets[i] = r.getSnippet();
                i++;
            }
            return getResults(snippets, urls, true);    
        } catch (IOException e) {
            // TODO Auto-generated catch block
            MsgPrinter.printSearchError(e);
            System.exit(1);
            return null;
        }
    }

kindly suggest me how it should be fixed.

Upvotes: 1

Views: 8739

Answers (4)

Glory
Glory

Reputation: 1077

Down load the Maven of jackson from here.

Then add it to your dependencies.

Upvotes: 0

AlikElzin-kilaka
AlikElzin-kilaka

Reputation: 36001

Happened to me when having 2 jackson versions - codehaus vs. fasterlxml. Removing the fasterxml version (that was a trans-dependency of swagger) fixed the issue.

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-jersey-jaxrs</artifactId>
    <version>1.5.3</version>
    <exclusions>
        <exclusion>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
        </exclusion>
        <!--<exclusion>-->
        <!--<groupId>com.fasterxml.jackson.datatype</groupId>-->
        <!--<artifactId>jackson-datatype-joda</artifactId>-->
        <!-- test -->
    </exclusions>
</dependency>

Upvotes: 1

CYMA
CYMA

Reputation: 677

To answer the question directly (it was answered in the comments by Pavel). The jackson core lib dependency was missing: jackson-core-$x.y.z.jar

Upvotes: 1

Justice O.
Justice O.

Reputation: 1313

I had a similar problem, eventually discovered it was an issue with the buildpath and dependencies. The easiest (not most efficient) is too add all the google-api-client jars to your project and it would disappear. Better way is to track and properly add all other dependencies of jacksonFactory

Upvotes: 0

Related Questions