简体   繁体   English

当我使用 -cp 时 Java 无法找到或加载主 class

[英]Java could not find or load main class when I use -cp

I have a problem.我有个问题。
I try to run my java program with the library.我尝试使用该库运行我的 java 程序。
When I use当我使用

java com/myProg

it works.有用。
But when I try to pass classpath it can't find or load main class但是当我尝试通过类路径时,它找不到或加载主 class

java -cp com/lib/lid.jar com/myProgram

error:错误:

Error: Could not find or load main class myProgram

Caused by: java.lang.ClassNotFoundException: myProgram引起:java.lang.ClassNotFoundException: myProgram

Try specifying after the -cp option only the root of the working directory and don't include the package name there.尝试在 -cp 选项之后仅指定工作目录的根目录,并且不要在其中包含 package 名称。 If you're running the java command from the dir of /com 's location, -cp. com/myProgram如果您从/com的位置目录运行 java 命令, -cp. com/myProgram -cp. com/myProgram will be enough,otherwise you'll need the fully qualified name after the classpath. -cp. com/myProgram就足够了,否则您将需要类路径后的完全限定名称。 Not sure of the necessity of the.jar file, you stated that first you ran only via java com/myProg .不确定.jar 文件的必要性,您说首先您仅通过java com/myProg

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

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