I have a very simple class file (.class) which I am fully sure it is working fine, when I do comment package assignment:
package com.domain.core;
public class Challenge {
public static final int ID = (int) Math.abs(Math.random()*10);
public static void getDescription() {
System.out.println("Challenge ID: " + ID);
}
public static void main(String args[]) {
getDescription();
}
}
I am testing this on Windows machine, through usual CMD. There is no global CLASSPATH specified. I have located .class file in the directory "myclasses" within C drive. So path to the class is: "C:\myclasses"
The purpose here is to run the class with the -classpath option of jvm. I have checked the following ways:
Within the C drive:
- java -cp "\myclasses" com.domain.core.Challenge
- java -cp \myclasses com.domain.core.Challenge
- java -cp .\myclasses com.domain.core.Challenge
- java -cp ".\myclasses" com.domain.core.Challenge
- java -cp "/myclasses" com.domain.core.Challenge
- java -cp /myclasses com.domain.core.Challenge
- java -cp ./myclasses com.domain.core.Challenge
- java -cp "./myclasses" com.domain.core.Challenge
Within the directory "C:\myclasses"
- java -cp "C:\myclasses" com.domain.core.Challenge
- java -cp C:\myclasses com.domain.core.Challenge
- java -cp "C:/myclasses" com.domain.core.Challenge
- java -cp C:/myclasses com.domain.core.Challenge
Replacing -cp with -classpath is resulting the same:
Error: Could not find or load main class com.domain.core.Challenge
JVM:
C:\>java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Really odd issue. Could you guys pin point what I do here wrong ?
Thanks!