如何设置 JAVAC 编译文件的输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36682472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set the output of a JAVAC compiled file
提问by zin
My previous question asked how to compile files with the command JAVAC
. I still don't know how to set the output file of the compiled data.
我之前的问题询问如何使用命令编译文件JAVAC
。我还是不知道如何设置编译数据的输出文件。
采纳答案by Jon Skeet
The output of javac
is always classfiles, and the name of the file matches the name of the class contained within it. (A source file with multiple classes in will result in multiple output files.)
的输出javac
始终是类文件,文件名与其中包含的类名相匹配。(包含多个类的源文件将产生多个输出文件。)
If you use the -d
command line option, javac
will also use the package of the class to generate a directory hierarchy, with the -d
option specifying the root. Otherwise, each class file will be output in the same directory as the source file from which it was compiled.
如果使用-d
命令行选项,javac
也会使用类的包来生成目录层次结构,用-d
选项指定根。否则,每个类文件将在与编译它的源文件相同的目录中输出。
回答by hd1
From man javac
on my system:
从man javac
我的系统上:
-d directory
Sets the destination directory for class files. The destination directory must already exist; javac will not create the destination 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/mypackage/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.
-d directory
设置类文件的目标目录。目标目录必须已经存在;javac 不会创建目标目录。如果类是包的一部分,javac 会将类文件放在反映包名称的子目录中,并根据需要创建目录。例如,如果您指定 -d /home/myclasses 并且类名为 com.mypackage.MyClass,则类文件名为 /home/myclasses/com/mypackage/MyClass.class。如果未指定 -d,则 javac 会将类文件放在与源文件相同的目录中。注意:-d 指定的目录不会自动添加到您的用户类路径中。
Hope that helps.
希望有帮助。