设置了类路径,但是java.lang.NoClassDefFoundError com / google / protobuf / MessageOrBuilder错误? [英] Classpath set but java.lang.NoClassDefFoundError com/google/protobuf/MessageOrBuilder error?

查看:1072
本文介绍了设置了类路径,但是java.lang.NoClassDefFoundError com / google / protobuf / MessageOrBuilder错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个使用protobuf.jar的Java程序,但我一直收到此错误。

I am trying to run a java program that uses protobuf.jar, but I keep getting this error.

我已在Linux中设置了classpath变量,以便:

I have set my classpath variable in linux so that:

 CLASSPATH=/home/.../src/PlaceServer.class:/home/.../src/protobuf.jar:/home/.../src
 export CLASSPATH

但是当我运行时

 java PServer 

我明白了:

 java.lang.NoClassDefFoundError: com/google/protobuf/MessageOrBuilder

但是,当我运行另一个也读取相同jar的程序时,这个叫做BServer

However when I run another program that also reads the same jar, this one called BServer

 java BServer

它可以正常工作,并且按我的要求正确运行。我什至尝试在这些命令下运行

It works fine, and correctly as I want it. I even tried running under these commands instead

 java -cp .protobuf.jar PServer

对于PServer仍然不起作用。

And it still did not work for PServer.

但是,如果我运行相同的从命令行在Macbook上运行程序(也在两种操作系统中都在Eclipse中)我没有收到此Exception,并且一切正常。

However, if I run the same programs on my Macbook from the command line (also in Eclipse in either OS) I do not get this Exception and it all works fine.

感谢您的帮助!

推荐答案

有几个要消除此错误,需要检查以下内容:

There are a couple of things to check to get rid of this error:


  • 验证所有必需的Java类都包含在应用程序的类路径中。最常见的错误是在开始执行依赖于某些外部库的Java应用程序之前,不包括所有必需的类。

  • 应用程序的类路径正确,但类路径正确在应用程序执行之前覆盖环境变量

在Eclipse中运行应用程序时,IDE通过使用内部的.classpath文件来解决此问题。项目文件夹。在构建应用程序(创建jar)时,您可能会意外忽略此类或更改其位置。

When you run the application in Eclipse, the IDE resolves this by using the .classpath file inside the project folder. When you build an application (create the jar), you could accidentally omit this class, or change its location.

您需要做的是首先打开jar,并确保所涉及的类实际上位于jar内,且路径相同。然后,浏览上面的列表。

What you need to do is to first open the jar, and make sure that the class in question is in fact inside the jar, in the same path. Then, go through the list above.

这篇关于设置了类路径,但是java.lang.NoClassDefFoundError com / google / protobuf / MessageOrBuilder错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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