I have the following simplified file structure:
C:/red/green/black/yellow/white/pink. I am now in cmd in folder 'black'.
The Hello.javafile has package yellow.white.pink in it. In folder 'pink' there is a Hello.java source file.
First I try to compile the file:
javac -classpath . -encoding ISO-8859-1 yellow.white.pink.Hello.java
javac -cp . -encoding ISO-8859-1 yellow.white.pink.Hello.java
These two give me an error:
File not found yellow.white.pink.Hello.java.
Then I try
javac -encoding ISO-8859-1 C:/red/green/black/yellow/white/pink/Hello.java
It compiles just fine.
To run it I do
java -classpath . yellow.white.pink.Hello
And it runs just fine.
But in this case
java C:/red/green/black/yellow/white/pink/Hello.class
doesn't work - gives Could not find or load main class error.
Why is that? Why can't I compile .java file when being in the root folder and giving a full package name and it works only with the whole path to the source, while the reverse is true for executing the program?
.javafile you can be located in cmd in any folder on your computer, while when running the.classfile using.packagename.ClassNamecommand you need to be located in a folder prior to the first one of thepackagename?