给出以下目录结构:
bigProject
|--source
| |--Utils.java
|
|--classes
|--
以下命令行调用: javac -d classes source / Utils.java 假设当前目录是bigProject,结果是什么?
A. If the compile is successful, Utils.class is added to the source directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to the classes directory.
D. If the compile is successful, Utils.class is added to the bigProject directory.
答案:C
任何人都可以解释一下,为什么答案是C。
答案 0 :(得分:2)
-d classes
命令行开关告诉编译器将已编译的代码存储在classes
文件夹中。
请参阅javac的documentation:
-d目录
设置类文件的目标目录。目标目录必须已存在; javac不会创建 目的地目录。如果一个类是包的一部分,那么javac会把它放到 反映包名的子目录中的类文件,创建 目录根据需要。例如,如果指定-d / home / myclasses 并且该类称为com.mypackage.MyClass,然后是类文件 叫/home/myclasses/com/mypackage/MyClass.class。
如果-d不是 指定后,javac将类文件放在与...相同的目录中 源文件。
答案 1 :(得分:1)
如果您在没有任何参数的情况下运行javac
,则会打印帮助内容
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...]Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-d
说-d <directory> Specify where to place generated class files