列出javac

时间:2018-05-31 00:02:28

标签: java classpath javac

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

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

1 个答案:

答案 0 :(得分:1)

  

javac可以在编译期间生成一个包含足够详细信息的日志吗?

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]