7

I am using jackson libs in my application and when I build the code (using ant), the build is successful. And I have tried mock testing by using those methods in unit testing and its working fine. But when starting karaf, it gives me this error:

Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JavaType not found by com.project.test.application [224]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

And these are the jars I am downloading in my ivy.xml:

<dependency org="com.fasterxml.jackson.core" name="jackson-core" rev="2.4.4" transitive="false" />
<dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.4.4" transitive="false" />
<dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.4.4" transitive="false" />

I have tried changing the versions, but still the same error. Do I have to load these jars after downloading? I have kept the default place as ivy-lib and that process is working for all the other jars I am downloading. What is going wrong? Does this require a specific version or any other dependency? Or is there other way to load these jar files?

My classpath in build.xml

<path id="compile.classpath">
    <fileset dir="${ivy.lib}">
      <include name="*.jar"/>
    </fileset>
</path>
Siddharth
  • 884
  • 3
  • 11
  • 27
  • where is your code for com.test.application class ? – Vasu Oct 29 '16 at 09:39
  • When running your test how are you specifying the classpath? You need to include more detail from your build.xml file. The class exists in the jackson-databind dependency: http://search.maven.org/#search%7Cga%7C1%7Cfc%3A%22com.fasterxml.jackson.databind.JavaType%22%20AND%20g%3A%22com.fasterxml.jackson.core%22%20AND%20v%3A%222.4.4%22 – Mark O'Connor Oct 29 '16 at 11:58
  • My classpath in build.xml is the ivy-lib folder. I updated my answer. – Siddharth Oct 29 '16 at 12:11

3 Answers3

11

I was getting this error because someone else in some other class was using org.codehaus.jackson package and I am using com.fasterxml.jackson package. And because of this conflict of jars, it was throwing this ClassNotFoundException. Once I removed and replaced those fasterxml jars with codehaus jars, it started working fine.

Siddharth
  • 884
  • 3
  • 11
  • 27
4

We can add below dependencies in our pom.xml and all type of jackson error will be resolved

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.4</version>
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.4.4</version>
    </dependency>

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

As for me, version 2.8.6 didn't work with Spring MVC context (w/o Boot) while 2.9.4 works fine.

tarmogoyf
  • 298
  • 3
  • 17