[英]Java main method not found error on Windows 10 even with correct main signature
I have a couple of Java files A.java and B.java that use a common jar file C.jar. 我有几个Java文件A.java和B.java使用共同的jar文件C.jar。 B.java contains reference variables to the object of type ABjava contains the main method
B.java包含对AB类型对象的引用变量Java包含main方法
I compiled using the following command. 我使用以下命令进行编译。
javac -cp C.jar A.java B.java
It compiles. 它编译。
However, when I run it says main method not found. 但是,当我运行它说找不到主要方法。
I ran 我跑了
java -cp C.jar B
Am I making some mistake in my commands? 我在命令中犯了一些错误吗?
Am I making some mistake in my commands?
我在命令中犯了一些错误吗?
Yes - you're not including anything apart from C.jar
when trying to run. 是的-尝试运行时,除了
C.jar
之外,您没有包括其他任何内容 。
Use 采用
java -cp C.jar;. // Windows
java -cp C.jar:. // Unix
So that you're including the current directory (which is where A.class
and B.class
are, presumably) on the classpath. 这样就可以在类路径中包括当前目录(大概是
A.class
和B.class
所在的目录)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.