[英]Is it possible to preview which class files will Java compiler generate?
Is there an option for javac
, say --dry-run
, that will instruct the compiler not to do the actual compilation, but to parse the source file(s) and list which .class
files (including package path) will be generated? 是否有一个
javac
选项,比如说--dry-run
,它会指示编译器不要进行实际的编译,而是解析源文件并列出将生成哪些.class
文件(包括包路径)?
Consider this example: 考虑这个例子:
$ cat example.java
package whatever.example;
class First {}
class Second {}
$ javac -d . example.java
$ find .
.
./example.java
./whatever
./whatever/example
./whatever/example/First.class
./whatever/example/Second.class
The source file was compiled into two .class
files and, as the -d
option was specified, package structure was generated. 源文件被编译为两个
.class
文件,并且在指定-d
选项时,生成了包结构。 I would like to know such information before compilation. 我想在编译之前知道这些信息。 Something like this:
像这样的东西:
$ javac --dry-run -d . example.java
./whatever/example/First.class
./whatever/example/Second.class
Alternatively, if there is no such an option for javac
, is there any third-party utility that can do such a thing? 或者,如果
javac
没有这样的选项,是否有任何第三方实用程序可以执行此类操作?
try 尝试
javac -verbose -d . javaclass.java
this actually lists all the actions that a compiler is working on. 这实际上列出了编译器正在处理的所有操作。 towards the end you can what all classes have been generated with package structure.
最后,您可以使用包结构生成所有类。
I have compiler via the above code. 我通过上面的代码编译。 I get the below output towards the end of the list.
我在列表末尾得到以下输出。
[wrote RegularFileObject[.\com\SC\JustTesting.class]]
[wrote RegularFileObject[.\com\SC\JustTestingSecond.class]]
There are lot of other options, just type javac
on the command prompt to look at them. 还有很多其他选项,只需在命令提示符下键入
javac
即可查看它们。
I don't know if I one can know, prior to compiling, this information. 在编译之前,我不知道是否可以知道这些信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.