简体   繁体   English

Java类路径设置错误

[英]Java classpath setting error

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. 在axis2目录中,我有Client.class文件。

Now, to run the Client class file, i gave the following command from src directory 现在,要运行Client类文件,我从src目录发出了以下命令

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? 我在这里做错了什么?

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; 当然,我假设您有package org.apache.ws.axis2; at the beginning of Client.java Client.java的开头

As it implies, the classpath is set to a path where you can find, well, classes 顾名思义,classpath设置为可以找到的路径

I think you might be having classes stored in the bin or the classes directory. 我认为您可能将类存储在binclasses目录中。

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 如果您在src旁边有类,则将其更改为

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. 类路径只能设置到包的根目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM