I have been using an IDE but now, in order to prepare my 1Z0-803 exam, I need to run and compile from the command line. The problem is that I have multiple packages and I have tried to find the answer but nothing has worked so far.
So I have :
package com.oca.tutorial;
import com.oca.tutorial.planets.Earth;
import com.oca.tutorial.planets.Mars;
import com.oca.tutorial.planets.Venus;
public class GreetingUniverse {
public static void main(String[] args) {
System.out.println("greetings universe");
new Earth();
new Mars();
new Venus();
}
}
Venus class:
package com.oca.tutorial.planets;
public class Venus {
public Venus() {
System.out.println("Hello from Venus");
}
}
Mars class
package com.oca.tutorial.planets;
public class Mars {
public Mars (){
System.out.println("Hello from Mars");
}
}
And my Earth class
package com.oca.tutorial.planets;
public class Earth {
public Earth (){
System.out.println("Hello from earth");
}
}
Command Line + error

Expected output:
greetings universe
Hello from earth
Hello from Mars
Hello from Venus
Fiel Structure for planets :
C:\OCA\com\oca\tutorial\planets
Fiel Structure for main GreetingUniverse :
C:\OCA\GreetingUniverse
error message from command prompt:

Make sure that all files can be found by the compiler. Go to the directory containing the com folder and use:
javac -d classes com\oca\tutorial\GreetingUniverse.java
or simply
javac -d classes com\oca\tutorial\*.java
with this file structure
com
|-oca
|-tutorial
| GreetingUniverse.java
|-planets
Earth.java
Mars.Java
Venus.java
You need to be located in C:\OCA when doing the compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With