91

I am working on YouTube broadcast sample examples. I have created a sample Java Project & added required jars. But, when I try to run the project it throws exception.

Exception :

Throwable: com/fasterxml/jackson/core/JsonFactory
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory
    at com.google.api.client.json.jackson2.JacksonFactory.<init>(JacksonFactory.java:44)
    at com.google.api.services.samples.youtube.cmdline.live.Auth.<clinit>(Auth.java:35)
    at com.google.api.services.samples.youtube.cmdline.live.CreateBroadcast.main(CreateBroadcast.java:55)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more

I downloaded the project from this GitHub repository.

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
VVB
  • 7,363
  • 7
  • 49
  • 83

15 Answers15

133

Add the following dependency to your pom.xml

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.5.2</version>
</dependency>
shruti1810
  • 3,920
  • 2
  • 16
  • 28
  • I am not using Maven but I downloaded this jar & added to project properties. It worked. Thanks shruti. Accepted + upvoted answer – VVB May 21 '15 at 08:36
  • 1
    I have no idea why this works. I already had version 2.3.3., which is where the error arrrived, but changing the version of (only) jackson-core to 2.5.2. Works. – Mindsect Team Aug 27 '17 at 16:34
  • I also needed to upgrade jackson dependency to a newer version, but this did not get the name added to my Manifest and therefore ClassNotFoundException was still thrown until I manually edited it. – Ryan D Nov 14 '18 at 20:16
40

If you are using springboot then jackson is added by default,

So the version of jackson you are adding manualy is probably conflicting with the one spring boot adds,

Try to delete the jackson dependencies from your pom,

If you need to override the version spring boots add, then you need to exclude it first and then add your own

ezzou
  • 2,348
  • 1
  • 15
  • 16
17

Because of old version I got this error. Then I changed to this version n error gone Using maven my pom.xml

<properties>  
    ...
    <jackson.version>2.5.2</jackson.version>
</properties>

<dependencies>
...
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
</dependencies>

my old version was '2.2.3'

raka
  • 556
  • 9
  • 18
asifaftab87
  • 1,315
  • 24
  • 28
12

In my case problem was when i added com.fasterxml.jackson.dataformat i put the version 2.11.0.

While all other Jackson dependencies were 2.8.0 and one of them was 2.11.0 and changing all to be 2.8.0 fixed it.

FYI, 2.11 is the latest but due to my legacy code, i kept it as 2.8 as well.

Before Fix [ERROR] : com.fasterxml.jackson.dataformat version is 2.11.0:

   <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>2.11.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.8.0</version>
    </dependency>

After Fix [WORKED] com.fasterxml.jackson.dataformat version is 2.8.0:

 <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.8.0</version>
    </dependency>
Hrvoje
  • 13,566
  • 7
  • 90
  • 104
shareef
  • 9,255
  • 13
  • 58
  • 89
6

I have had the same error. I added dependency on pom.xml (I am working with Maven)

<dependency> 
        <groupId>com.fasterxml.jackson.core</groupId> 
        <artifactId>jackson-core</artifactId> 
        <version>2.12.1</version> 
 </dependency> 

I started trying with version 2.9.0, then I found a different error (com/fasterxml/jackson/core/exc/InputCoercionException) then I try different versions until all errors were solved with version 2.12.1

Yanpol
  • 61
  • 1
  • 1
5

The requested jar is probably not jackson-annotations-x.y.z.jar but jackson-core-x.y.z.jar which could be found here: http://www.java2s.com/Code/Jar/j/Downloadjacksoncore220rc1jar.htm

4

The issue was conflicting version of Jackson-databind. My spring-boot version was 2.5.8, and spring-boot was using jackson-core version 2.12.6.

My explicit implementation was using jackson-core version 2.13.2, and this was the cause of the problem.

I commented out the below line from gradle.build, and this fixed the issue.

implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.2'
Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42
  • This give me the hint that the problem was a conflict between versions. I didn't know that spring-boot already have jackson dependencies. – Gi1ber7 Oct 13 '22 at 17:40
  • Thanks Gi1ber7. If the answer has helped your in solving your problem, kindly upvote. :) – Muhammad Tariq Oct 16 '22 at 09:56
3

Solved the problem by upgrading the dependency to below version

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.8</version>
</dependency>
Arpan Saini
  • 4,623
  • 1
  • 42
  • 50
2

You have to add one jar : jackson-annotations-2.1.2.jar You can download it from here and add it to the class path If you are using the gradle then add the following dependency.

compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.5.2'
Kartheek
  • 7,104
  • 3
  • 30
  • 44
2

As of jackson 2.7.4 (or earlier maybe), the class is in jacskon-jaxrs-base.jar, which is contained in jackson-jaxrs-json-provider

Cec
  • 1,726
  • 3
  • 18
  • 31
1

I faced the same issue and this was happening due to conflicting Jackson version present in the project.

So I explicitly defined the same version for all the Jackson dependencies in my pom.xml. Post this I did not face the error while running jar and it was properly resolved.

Below is what I used:

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.12.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.12.0</version>
    </dependency>

Maven Dependency tree with conflicting version

(base) rohiagra-mac:test-secret rohiagra$ mvn dependency:tree|grep jackson
[INFO] |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.7.9:compile
[INFO] |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.7.9:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.7.9:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.12.0:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.0:compile
[INFO] |  +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.32:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.9:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile

Maven Dependency tree with resolved conflicts

[INFO] |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.7.9:compile
[INFO] |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.7.9:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.7.9:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.0:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.0:compile
[INFO] |  +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.32:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.9:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.0:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.12.0:compile
Rohit Agrawal
  • 191
  • 1
  • 5
1

Most of time it is Jackson version incompatibility. Upgrade the jackson version and it should work.

Rajnish
  • 58
  • 5
1

I fixed this issue by simply removing the version tag as follows:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
</dependency>
ahmnouira
  • 1,607
  • 13
  • 8
1

I have faced the same issue on my project Java 17, I have used the dependency.

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.13.1</version>
        </dependency>

Note that the version of jackson is automatically added by spring boot, you don't really need to add it manually.

I have removed it from the pom.xml

AceneKASDI
  • 339
  • 3
  • 8
1

I've reproduced the issue like:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/JacksonFeature

with version of dependency:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.13.3</version>
</dependency>

and:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.1</version>
</dependency>

To fix it, I've used:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.10.1</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.10.1</version>
</dependency>
invzbl3
  • 5,872
  • 9
  • 36
  • 76