Search code examples
javajavac

Explanation and usage of -d option in java


How does -d works in java please anybody can give the explanation of this.


Solution

  • From the docs:

    -d directory
    

    Sets the destination directory for class files. If a class is part of a package, then javac puts the class file in a subdirectory that reflects the package name and creates directories as needed.

    For example:

    Oracle Solaris, Linux, and OS X: If you specify

    -d /home/myclasses and the class is called com.mypackage.MyClass
    

    then the class file is /home/myclasses/com/mypackage/MyClass.class.

    Windows: If you specify

    -d C:\myclasses and the class is called com.mypackage.MyClass
    

    then the class file is C:\myclasses\com\mypackage\MyClass.class.

    If the -d option isn’t specified, then javac puts each class file in the same directory as the source file from which it was generated.