MongoDB with java Exception in thread" main" java.lang.NoClassDefFoundError:org / bson / conversions / Bson [英] MongoDB with java Exception in thread "main" java.lang.NoClassDefFoundError: org/bson/conversions/Bson

查看:1375
本文介绍了MongoDB with java Exception in thread" main" java.lang.NoClassDefFoundError:org / bson / conversions / Bson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从intelliJ Idea执行mycode时,它工作正常但是当我在服务器上运行jar时会抛出以下错误。我正在使用'org.mongodb:mongodb-driver:3.4.1'版本。

When I execute mycode from intelliJ Idea it works fine but when I run the jar on my server it throws the below error. I am using 'org.mongodb:mongodb-driver:3.4.1' version.

 Exception in thread "main" java.lang.NoClassDefFoundError: org/bson/conversions/Bson
        at com.myapp.server.mongo.MongoDbHandler.prepareMongoDb(MongoDbHandler.java:68)
        at com.myapp.server.mongo.MongoDbHandler.<init>(MongoDbHandler.java:22)
        at com.myapp.server.Client.main(Client.java:167)
Caused by: java.lang.ClassNotFoundException: org.bson.conversions.Bson
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 3 more


推荐答案

我知道它是一个旧线程,它只适用于那些有类似问题的人。几天前我在使用命令行运行jar时也面临同样的错误跟踪问题。重新检查代码后发现

I know its an old thread and its just for those who have the similar issues. Few days back I was also facing the same issue with same error trace while running the jar by command line.After rechecking the code found that


这不是jar版本的问题,但它的包装问题是
jar

It was not a problem of the jar version but its problem of the packaging of the jar

打包后用jar包装所有正确的依赖都将解决这个问题。

After packing the jar with all proper dependencies will solve this issue.

我用过


maven- assembly-plugin

maven-assembly-plugin

包装及其作品。

这篇关于MongoDB with java Exception in thread&quot; main&quot; java.lang.NoClassDefFoundError:org / bson / conversions / Bson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆