How to Run a java compiled file from a package in the Windows Command Prompt?

45 views Asked by At

How to Run a java compiled file from a package in the Windows Command Prompt?

D:\eclipse-workspace-ghj2\ExecJava\src\pkg>javac Manager_1.java

D:\eclipse-workspace-ghj2\ExecJava\src\pkg>java pkg.Manager_1

Error: Could not find or load main class pkg.Manager_1 Caused by: java.lang.ClassNotFoundException: pkg.Manager_1

I tried to run a java compiled class from a package.
Error: Could not find or load main class pkg.Manager_1

1

There are 1 answers

0
aled On

You are in directory pkg so java can not find the package pkg there. You need to be in the top directory of your packages (D:\eclipse-workspace-ghj2\ExecJava\src\ in your case) to execute the command so Java can find the package and then the class.