gpt4 book ai didi

java - 列出javac编译的Java源文件

转载 作者:行者123 更新时间:2023-12-02 11:11:06 31 4
gpt4 key购买 nike

我有一系列小型 Java 项目(*.java 文件中的类),它们通过 CLASSPATH 引用大型代码存储库。代码存储库包含大量的*.java 文件(源文件)和一些*.jar 文件。我想将任何给定的项目与其目录分开,以便打包并分发它。

给定一个包含 main 方法作为给定项目起点的 Java 类,如何列出 CLASSPATH 上用于编译给定 Java 的所有文件,例如 *.java 文件或 *.jar 文件类(class)? javac 在编译过程中能否生成包含足够详细信息的日志?您可以单独使用Java API并以编程方式检查用于编译的源文件吗?

最佳答案

Can javac produce a log with sufficient details during compilation?

javac具有 -verbose 选项,可让您了解哪些 JAR 位于类路径上以及编译了哪些 Java 文件。

javac -verbose <filepath>

示例输出(编译使用 Dummy2.java 和一些 JDK 类的 Dummy.java):

[parsing started RegularFileObject[Dummy.java]]
[parsing completed 10ms]
[search path for source files: .]
[search path for class files: C:\Program Files\Java\jdk1.7.0_80\jre\lib\resources.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\rt.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\sunrsasign.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\jsse.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\jce.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\charsets.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\jfr.jar,C:\Program Files\Java\jdk1.7.0_80\jre\classes,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\access-bridge-64.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\dnsns.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\jaccess.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\localedata.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunec.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunjce_provider.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunmscapi.jar,C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\zipfs.jar,.]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/io/File.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
[checking Dummy]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/AutoCloseable.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/net/URI.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/System.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/io/PrintStream.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/io/FilterOutputStream.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/io/OutputStream.class)]]
[loading RegularFileObject[.\Dummy2.java]]
[parsing started RegularFileObject[.\Dummy2.java]]
[parsing completed 0ms]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/StringBuilder.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/CharSequence.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/io/Serializable.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Comparable.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/AbstractStringBuilder.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_80\lib\ct.sym(META-INF/sym/rt.jar/java/lang/StringBuffer.class)]]
[wrote RegularFileObject[Dummy.class]]
[checking Dummy2]
[wrote RegularFileObject[.\Dummy2.class]]
[total 257ms]

关于java - 列出javac编译的Java源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614894/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com