Java类路径设置错误
即使我正确设置了类路径,我仍然收到“无法找到或加载主类”错误。
这是我的目录结构:
src\org\apache\ws\axis2
在 axis2 目录中,我有我的 Client.class 文件。
现在,为了运行 Client 类文件,我从 src 目录给出了以下命令
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src\org\apache\ws\axis2" org\apache\ws\axis2\Client
,我也尝试了这个:
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src\org\apache\ws\axis2" org.apache.ws.axis2.Client
并且我得到了相同的错误。我在这里做错了什么?
I am getting "could not find or load main class" error even though i am setting the class path correctly.
Here is my directory structure:
src\org\apache\ws\axis2
Inside axis2 directory, i have my Client.class file.
Now, to run the Client class file, i gave the following command from src directory
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src\org\apache\ws\axis2" org\apache\ws\axis2\Client
I tried this as well:
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src\org\apache\ws\axis2" org.apache.ws.axis2.Client
And i get the same error. What am i doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不应该是
类路径应该引用包结构的根目录,而不是内部包的特定文件夹。当然,我假设您在
Client.java
的开头有package org.apache.ws.axis2;
Shouldn't it be
Class path should refer to the root of your package structure, not to the specific folder of the inner package. Of course I'm assuming you have
package org.apache.ws.axis2;
at the beginning ofClient.java
顾名思义,类路径设置为您可以找到类的路径,
我认为您可能将类存储在
bin
或classes中目录。
将命令行更改为:
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\classes" org.apache.ws.axis2.Client
如果您有这些类src,然后将其更改为
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src" org.apache.ws.axis2.Client
类路径只能设置到包的根目录。
As it implies, the classpath is set to a path where you can find, well, classes
I think you might be having classes stored in the
bin
or theclasses
directory.Change your command line to:
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\classes" org.apache.ws.axis2.Client
If you have the classes alongside src, then change it to
java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src" org.apache.ws.axis2.Client
Classpaths should only be set till the root of the package.