An example of what a java command should look like:
java -Xmx100m com.acme.example.ListUsers fred joe bert
The above is going to cause the java command to do the following:
- Search for the compiled version of the
com.acme.example.ListUsersclass. - Load the class.
- Check that the class has a
mainmethod with signature, return type and modifiers given bypublic static void main(String[]). (Note, the method argument's name is NOT part of the signature.) - Call that method passing it the command line arguments ("fred", "joe", "bert") as a
String[].
Q1. javac: file not found: polymorphism.music.Music.java
A1: instead use
$ javac polymorphism/music/Music.java
also use absolute classpath, for example,
javac ~/user/polymorphism/music/Music.java
Q2: Error: Could not find or load main class polymorphism.music.Music
A1: be sure already has Music.class, then use
$ java polymorphism.music.Music
or
java polymorphism/music/Music
If you want use javac/java in current directory, you need modify source code. Remove package sentences and some comments in exmaples code.
refereces:
1. https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean
Java命令解析与常见错误
本文详细解析了Java命令的基本格式,包括如何指定最大内存、加载并运行特定类的方法,以及如何传递命令行参数。同时,针对常见的编译和运行时错误,如文件未找到、主类找不到等问题,提供了具体的解决步骤和建议。
4万+

被折叠的 条评论
为什么被折叠?



