简体   繁体   English

即使使用正确的主签名也无法在Windows 10上找到Java主要方法错误

[英]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.classB.class所在的目录)。

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

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