Java Example – How to Execute a Specified Class File Directory (classpath)
If our compiled Java class file is not in the current directory, we can use -classpath to specify the class file directory:
C:> java -classpath C:\java\DemoClasses HelloWorld
In the above command, we used the -classpath parameter to specify the directory where the HelloWorld class file is located.
If the class file is in a jar file, the command is as follows:
c:> java -classpath C:\java\myclasses.jar
Java Examples