[英]java.lang.NoClassDefFoundError: com/mongodb/XXXXXX Can't fix it! (Using: MongoDB Java Driver, Spigot)
I'm writing a plugin for Spigot/Bukkit (Minecraft) in Java and can't figure out how to fix this problem for the life of me. 我正在用Java为Spigot / Bukkit(Minecraft)写一个插件,却想不通如何解决这个问题。 Although I have done a lot of programming in other languages, this is my first attempt at programming in java.
尽管我已经用其他语言进行了大量编程,但这是我第一次尝试用Java编程。 I have done many google searches, looked at dozens of pages, but everything just said to do things I have already tried.
我已经做了很多Google搜索,看了几十页,但所有内容都只是说做我已经尝试过的事情。
I'm using eclipse and have converted my project to and from a maven project trying all sorts of variations of installing the mongo java driver. 我正在使用eclipse,并已将我的项目与maven项目进行了转换,并尝试了安装mongo java驱动程序的各种变化。 I've tried:
我试过了:
- Adding dependency/s -添加依赖性
- Adding it to the buildpath using project->properties->Java Build Path->Add External Jar -使用project-> properties-> Java Build Path-> Add External Jar将其添加到buildpath
- I've done a combination of both of the above -我同时完成了上述两项操作
- I've tried using mongodb-driver, mongodb-driver-core and bson together, and with mongodb-java-driver(which should just work on it's own.) -我尝试过将mongodb-driver,mongodb-driver-core和bson一起使用,并与mongodb-java-driver(应单独使用)一起使用。
- I've tried just using mongodb-java-driver -我尝试过仅使用mongodb-java-driver
- I've tried using many different versions of the drivers. -我尝试使用许多不同版本的驱动程序。
It doesn't matter what I do, when I export my plugin to a jar and attempt to run it on my spigot server I get the following error: 我做什么都没关系,当我将插件导出到jar并尝试在spigot服务器上运行它时,出现以下错误:
java.lang.NoClassDefFoundError: com/mongodb/MongoClientURI
Where MongoClientURI could be replaced by any mongo class I use in my code. 我的代码中可以使用任何mongo类替换MongoClientURI的地方。 Am I not using the driver correctly, am I missing something?
我是否没有正确使用驱动程序,是否缺少某些东西? What's going on?
这是怎么回事?
So I solved my own problem in the end. 所以我最终解决了自己的问题。 Turns out spigot doesn't recognize any jar files other than spigot plugins on execution.
事实证明,在执行时,除了spigot插件,spigot不能识别任何jar文件。 Shading would've solved my issue but instead I did this, which also works:
阴影可以解决我的问题,但是我做到了,这也可以:
Added the following to the file: 在文件中添加了以下内容:
Manifest-Version: 1.0 清单版本:1.0
Class-Path: libs/mongo-java-driver-3.2.2.jar 类路径:libs / mongo-java-driver-3.2.2.jar
Created-By: 1.7.0_06 (Oracle Corporation) 创建时间:1.7.0_06(Oracle公司)
Selected "Use existing manifest from workspace" in the final step of exporting my plugin. 在导出插件的最后一步中,选择了“使用工作空间中的现有清单”。
This meant that at runtime spigot would include {plugin location}/libs/mongo-java-driver-3.2.2.jar in it's libraries. 这意味着在运行时,子程序将在其库中包含{plugin location} /libs/mongo-java-driver-3.2.2.jar。
I found my solution here: https://www.spigotmc.org/threads/solved-mongodb-help.35922/ 我在这里找到了解决方案: https : //www.spigotmc.org/threads/solved-mongodb-help.35922/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.