Error: Could Not Find or Load Main Class

How to run a jar file?

To run a JAR (Java Archive) file, follow these steps given below:

Step 1: Install Java

Make sure you have Java installed on your computer. You can check if Java is installed by opening a command prompt or terminal window and typing:

java -version

If the single hyphon – does not work then use double hyphon:

java --version

If either command shows the output like below:

openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)

Note: If you have installed the other version of the JDK then you may see the different output.

If Java is not installed, then you can visit the post Set Up Java Development Environment.

Step 2: Navigate to the JAR File

Open a command prompt or terminal window. Use the cd command to navigate to the directory where your JAR file is located. For example, if your JAR file is on the desktop, you can navigate to it like this:

cd Desktop

Step 3: Run the JAR File

To run the JAR file, use the following command:

java -jar yourFile.jar

Using the above command you should be able to run your Java jar file.


Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments