我想在默认目录下创建一个名为“blue”的包。 所以,包声明是
package blue;
位于我的源代码的最顶层。当我用
编译文件时javac This.java
在命令提示符下,它完全忽略了我的包声明 并将类文件存储在默认目录中。它做到了这一点 无论目录“blue”是否在默认目录下。
但是当我用
编译时javac -d . This.java
它正在做它应该做的事情 - 创建包目录“blue” 默认情况下,将类文件存储在那里。我错过了什么?
提前感谢您的帮助。
答案 0 :(得分: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.