引起:java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JavaType not found

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40317682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:35:49  来源:igfitidea点击:

Caused by: java.lang.ClassNotFoundException: com.fasterxml.Hymanson.databind.JavaType not found

javajsonantHymanson

提问by Siddharth

I am using Hymanson 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:

我在我的应用程序中使用 Hymanson libs,当我构建代码(使用 ant)时,构建成功。我已经尝试通过在单元测试中使用这些方法进行模拟测试并且它工作正常。但是在启动 karaf 时,它给了我这个错误:

Caused by: java.lang.ClassNotFoundException: com.fasterxml.Hymanson.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.access0(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:

这些是我在 ivy.xml 中下载的 jars:

   <dependency org="com.fasterxml.Hymanson.core" name="Hymanson-core" rev="2.4.4" transitive="false" />
    <dependency org="com.fasterxml.Hymanson.core" name="Hymanson-annotations" rev="2.4.4" transitive="false" />
    <dependency org="com.fasterxml.Hymanson.core" name="Hymanson-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?

我已经尝试更改版本,但仍然出现相同的错误。下载后我必须加载这些 jars 吗?我将默认位置保留为 ivy-lib,并且该过程适用于我正在下载的所有其他 jar。出了什么问题?这是否需要特定版本或任何其他依赖项?或者还有其他方法可以加载这些 jar 文件吗?

My classpath in build.xml

我在 build.xml 中的类路径

<path id="compile.classpath">
      <fileset dir="${ivy.lib}">
         <include name="*.jar"/>
      </fileset>
   </path>

采纳答案by Siddharth

I was getting this error because someone else in some other class was using org.codehaus.Hymansonpackage and I am using com.fasterxml.Hymansonpackage. 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.

我收到此错误是因为其他班级中的其他人正在使用org.codehaus.Hymanson包而我正在使用com.fasterxml.Hymanson包。由于这种罐子的冲突,它抛出了这个ClassNotFoundException. 一旦我用codehaus jars删除并替换了那些fasterxml jars,它就开始正常工作了。

回答by Senthil Kumar

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

我们可以在 pom.xml 中添加以下依赖项,所有类型的 Hymanson 错误都将得到解决

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

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