This example covers common errors with using the ‘java’ command.
If you get an error message like:
java: command not found
when trying to run the java
command, this means that there is no java
command on your shell’s command search path. The cause could be:
PATH
environment variable (correctly) in your shell initialization file, orRefer to “Installing Java” for the steps that you need to take.
This error message is output by the java
command if it has been unable to find / load the entry-point class that you have specified. In general terms, there are three broad reasons that this can happen:
Here is a procedure to diagnose and solve the problem:
- If you have source code for a class, then the full name consists of the package name and the simple class name. The instance the "Main" class is declared in the package "com.example.myapp" then its full name is "com.example.myapp.Main".
- If you have a compiled class file, you can find the class name by running `javap` on it.
- If the class file is in a directory, you can infer the full class name from the directory names.
- If the class file is in a JAR or ZIP file, you can infer the full class name from the file path in the JAR or ZIP file.
java
command. The message should end with the full class name that java
is trying to use.- Check that it exactly matches the full classname for the entry-point class.
- It should not end with ".java" or ".class".
- It should not contain slashes or any other character that is not legal in a Java identifier<sup>1</sup>.
- The casing of the name should exactly match the full class name.