2

我正在寻找在默认目录下创建一个名为“blue”的包。所以,包声明是

package blue;

在我的源代码的最顶部。当我编译文件时

javac This.java 

在命令提示符下,它完全忽略了我的包声明并将类文件存储在默认目录中。无论默认目录下是否存在目录“blue”,它都会执行此操作。

但是当我编译时

javac -d . This.java

它正在做它应该做的事情——在默认情况下创建包目录“蓝色”并将类文件存储在那里。我错过了什么?

提前感谢帮助。

4

1 回答 1

4

来自man javac

  -d directory
            Set the destination directory for class files. The destination
            directory must already exist; javac will not create the desti‐
            nation directory. 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
            /home/myclasses and the class is called com.mypackage.MyClass,
            then the  class  file  is  called  /home/myclasses/com/mypack‐
            age/MyClass.class.

         If  -d  is  not  specified, javac puts the class file in the same
         directory as the source file.

         Note:   The directory specified by -d is not automatically  added
         to your user class path.
于 2012-11-16T05:47:38.890 回答