简体   繁体   English

是否可以预览Java编译器生成哪些类文件?

[英]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.

相关问题 是否可以使用Java Reflection API从.class文件生成.java文件? - Is it possible to generate .java files from .class files using Java Reflection API? 引入D8 dexer之后,Android当前使用哪个编译器将Java编译为.class文件? - Which compiler is currently used in android to compile Java to .class files after D8 dexer was introduced? 是否可以使用可在Java 6 JVM上运行的Java 7 SDK编译类文件? - Is it possible to compile class files with the Java 7 SDK which can run on Java 6 JVMs? clojure是否有可能读取和处理由编译器生成的类(.class文件)? - is it possible for clojure to read and work on classes (.class files) generated by compiler? 是否有Java库从AST生成类文件? - Is there a Java library to generate class files from an AST? 如何从jdk 15中提取java预览class文件? - How to extract java preview class files from jdk 15? 是否可以从spring-beans.dtd生成的spring-beans.xsd生成Java源文件? - Is it possible to generate java source files from a spring-beans.xsd which is generated from the spring-beans.dtd? 设置了CLASSPATH,但是Java编译器找不到类文件 - CLASSPATH set but java compiler cannot find class files 是否可以强制 Java 8 编译器创建可重现的类文件? - Can the Java 8 compiler be forced into creating reproducible class files? 休眠-如何为Java类正确生成.hbn.xml映射文件,该类对应于具有复合主键的表? - hibernate - how to properly generate .hbn.xml mapping files for a java class, which corresponds to a table with a composite primary key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM