Search code examples
javajavac

Does the javac command automatically create directories specified in the package declaration?


I've always used an IDE when working with Java so my knowledge on the javac command isn't that great. I want to know this: Does java generate the directories where the .class files should be placed in as specified in the .java files package declarations? Let me clarify, say you have a simple .java file like this on your Desktop:

package com.deangrobler.test

public class Test {

    // ...

}

When running the following from your Desktop:

javac Test.java

Will it then automatically go and create the com/deangrobler/test directories and place the Test.class file therein?


Solution

  • From the docs --> http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html See the option section.

    -d directory

    Set the destination directory for class files. The directory must already exist; javac will not create it. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d C:\myclasses and the class is called com.mypackage.MyClass, then the class file is called C:\myclasses\com\mypackage\MyClass.class. If -d is not specified, javac puts each class files in the same directory as the source file from which it was generated.

    Note: The directory specified by -d is not automatically added to your user class path.