-3

给定以下目录结构:

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。

4

2 回答 2

2

-d classes命令行开关告诉编译器将编译后的代码存储在classes文件夹中。

请参阅javac 的文档

-d 目录

设置类文件的目标目录。目标目录必须已经存在;javac 不会创建目标目录。如果类是包的一部分,javac 会将类文件放在反映包名称的子目录中,并根据需要创建目录。例如,如果您指定 -d /home/myclasses 并且类称为 com.mypackage.MyClass,则类文件称为 /home/myclasses/com/mypackage/MyClass.class。

如果未指定 -d,javac 会将类文件放在与源文件相同的目录中。

于 2013-07-14T17:00:25.360 回答
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

于 2013-07-14T17:03:28.537 回答