Java类路径设置错误

发布于 2025-01-06 23:29:23 字数 542 浏览 2 评论 0原文

即使我正确设置了类路径,我仍然收到“无法找到或加载主类”错误。

这是我的目录结构:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎无痕… 2025-01-13 23:29:23

不应该是

java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src" org.apache.ws.axis2.Client

类路径应该引用包结构的根目录,而不是内部包的特定文件夹。当然,我假设您在 Client.java 的开头有 package org.apache.ws.axis2;

Shouldn't it be

java -cp "C:\Documents and Settings\F1QBWFA\My Documents\Downloads\temp\src" org.apache.ws.axis2.Client

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 of Client.java

猫性小仙女 2025-01-13 23:29:23

顾名思义,类路径设置为您可以找到的路径,

我认为您可能将类存储在binclasses中目录。

将命令行更改为:

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 the classes 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文