可怕的java.lang.NoClassDefFoundError(The dreaded java.lang.NoClassDefFoundError)
我已经浏览了很多关于这个错误的现有线索,但仍然没有运气。 我甚至没有试图打包jar或使用任何第三方打包工具。 我只是从Eclipse内部运行(很好),然后尝试从命令行运行完全相同的应用程序,在它构建的相同位置(出现此错误)。 我的目标是能够压缩bin文件夹并通过命令行脚本将其发送给其他人运行。 一些细节:
- 这是一个命令行应用程序,我将commons-lang-2.4.jar用于字符串实用程序。 这是无法找到的文件(特定于“java.lang.NoClassDefFoundError:org / apache / commons / lang / StringEscapeUtils”)
- 我有我的lib文件夹中的jar,并通过右键单击“Build Path - > Add to Build Path”将它添加到Eclipse中的构建路径中
- .classpath文件看起来是正确的,并包含对jar的引用,但我认为该文件仅供Eclipse使用(包含以下行:
<classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
)- 这可能与Eclipse工作目录设置有关吗? 我创建了一些内部模板文件,这些模板文件位于src / templates下,并且我似乎可以看到这些内容的唯一方式是将项目工作目录设置为AppName / src。 也许我应该把这些放在别的地方?
让我知道,如果任何额外的信息会有所帮助。 当然这很简单,但是在这一点上我浪费了太多时间。 这提醒了我为什么最初在2005年左右将Java留在了......
I've looked through many of the existing threads about this error, but still no luck. I'm not even trying to package a jar or use any third-party packaging tools. I'm simply running from within Eclipse (works great) and then trying to run the exact same app from the command line, in the same location it's built to (getting this error). My goal is to be able to zip up the bin folder and send it off to be run by someone else via a command line script. Some details:
- It's a command-line app and I'm using the commons-lang-2.4.jar for string utilities. That is the file that cannot be located (specificaly "java.lang.NoClassDefFoundError: org/apache/commons/lang/StringEscapeUtils")
- I have that jar in my lib folder and have added it to my build path in Eclipse via right-click "Build Path -> Add to Build Path"
- The .classpath file looks correct and contains the reference to the jar, but I assume that file is only used by Eclipse (contains this line:
<classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
)- Could this be related to the Eclipse working directory setting? I have some internal template files that I created that are under src/templates, and the only way I can seem to get those to be seen is by setting the project working directory to AppName/src. Maybe I should be putting those somewhere else?
Let me know if any additional info would help. Surely this is something simple, but I've wasted too much time on it at this point. This is reminding me why I originally left Java back in '05 or so...
原文:https://stackoverflow.com/questions/1702852
最满意答案
您可以通过
Model#schema
访问Mongoose模型的Model#schema
,所以您可以:// Ensure the base model is defined first. require('./base.server.model.js'); var RegionSchema = new Schema({ name: {type: String}, user: {type: Schema.ObjectId, ref: 'User'}, bases: [mongoose.model('Base').schema] }); mongoose.model('Region', RegionSchema);
You can access a Mongoose Model's schema via
Model#schema
, so you can do:// Ensure the base model is defined first. require('./base.server.model.js'); var RegionSchema = new Schema({ name: {type: String}, user: {type: Schema.ObjectId, ref: 'User'}, bases: [mongoose.model('Base').schema] }); mongoose.model('Region', RegionSchema);
相关问答
更多-
我没有正确地将子文档推入文档。 这是将具有自己的ID字段的子文档推送到文档中的正确方法: db.locations.update({ "name" : "Starcups", }, { $push: { 'reviews' : { author: 'kyle riggen1', _id: new ObjectId(), rating: 4, timestamp: new Date("Jun 1, 2015"), reviewTe ...
-
如何使用来自另一个子文档的数据填充Mongoose子文档(How to populate Mongoose subdocument with data from another subdocument)[2022-09-26]
您可以在Mongoose的填充路径中使用点表示法来指定要填充的子文档层次结构中的路径: Club.findOne().populate('seasons.seasonPlayers.player').exec(function(err, club) {...}); You can use dot notation in Mongoose's population path to specify the path within the subdocument hierarchy to populate: C ... -
您不应该需要findOneAndUpdate,因为您已经拥有了linkedItem const linkedItem = item.linkedItems.id(linkedItemId); 所以你可以设置这些属性,然后使用.save() linkedItem.score = newAverageScore; linkedItem.currentNumberOfRatings = currentTotalNumberOfRatings; item.save(function(err, result){ ...
-
您可以使用$inc运算符。 见文档 。 Polls.findOneAndUpdate({ _id: req.params.id, responses._id: req.body._id }, { {$inc: {'responses.$.votes': 1}} }); Found a solution: Basically just use findOne to narrow down the id, then perform the que ...
-
我解决了这个问题: mainDoc[subDocFieldName].id(sudocId); 其实我在使用subDocument数组。 I solved this problem by : mainDoc[subDocFieldName].id(sudocId); Actually I was using subDocument array.
-
您可以通过Model#schema访问Mongoose模型的Model#schema ,所以您可以: // Ensure the base model is defined first. require('./base.server.model.js'); var RegionSchema = new Schema({ name: {type: String}, user: {type: Schema.ObjectId, ref: 'User'}, bases: [mongoose.m ...
-
猫鼬,从子文档拉(Mongoose, pull from subdocument)[2023-04-27]
似乎只有元素具有_id属性时, MongooseArray#pull方法才有效。 我发现使用直接调用update更容易,以避免这些惊喜: mongoose.model('organization').update( {_id: user.organization}, {$pull: {members: {user: user._id}}}, function(err, numAffected) { ... } ); It appears that the MongooseArray ... -
您需要单独定义子文档: var Reply = new mongoose.Schema({ body: String, created_at: { type: Date, default: Date.now } }); // Virtual must be defined before the subschema is assigned to parent schema Reply.virtual("created_at").get(function() { // ...
-
是的,您的架构是正确的。 可以在此处找到mongoose嵌套模式(SubDocuments)的文档 Yes, your schema is correct. The docs for mongoose nested schema (SubDocuments) can be found here
-
要删除特定用户的特定项,可以使用$pull运算符删除具有原子更新的子文档: User.user.update( { "_id": req.session.passport.user }, { "$pull": { "stuff": { "_id": req.params.id } } }, function(err, numAffected) { if(err){ console.log(err); } else { ...