I was studying the Java package system. I read something from foruns and from the Oracle docs.
My idea was create two classes. Put them in different packages, and use the import keyword to make all run.
The Class01 is like this:
package study.lab03;
public class Class01{
public void execute(){
System.out.println("test ok");
}
}
The Class02 is like this:
package study;
import study.lab03.*;
public class Class02{
public static void main(String[] args){
Class01 cl01 = new Class01();
cl01.execute();
}
}
My folder structure is like this: C:\projects\study\lab03
I have added 'C:\projects' to the final of the CLASSPATH variable.
To compile Class01 I did: C:\projects\study\lab03> javac Class01.java Compilation was good and the .class file was created.
To compile Class02 I did: C:\projects\study>javac Class02.java Compilation was good again and the .class was created.
To run the code I'm trying:
C:\projects\study>java Class02 Error: Impossible to find or load the main class
C:\projects\study>java -classpath projects Class02 Error: Impossible to find or load the main class
C:\projects\study>java -classpath projects study.Class02 Error: Impossible to find or load the main class
I can't understand what I'm doing wrong.