Search code examples
javaclasspathjavac

Can anyone please explain me the below command?


I am reading a tutorial in which, two files Helper.java and Main.java are created and below command is executed.

javac -d classes -sourcepath src src\com\mantiso\Helper.java

But, when I am trying to execute this command I am getting error that directory not found- Classes. As per my understanding, it will create one directory as classes. Please let me know if I am wrong.

Helper.java -

package com.mantiso;

public class Helper{
    public String getMessage(){
          return "Hello from Helper";
         }
}

Main.java -

package com.pluralsight;

public class Main {

    public static void main(String[] args) {
        com.mantiso.Helper helper = new com.mantiso.Helper();
        System.out.println(helper.getMessage());
    }
}

Solution

  • Below is the explanation of the command your trying to execute.

    javac -d classes -sourcepath src src\com\mantiso\Helper.java

    -d specifies the destination dir for the class files which will be created. You here we should have classes dir.

    -sourcepath specifies the source path i.e., where it should search for the source code.

    For debugging, the first step should be to make sure that we have all the required directories and source code available.

    To learn about more options which can be used with javac please refer this documentation.