如何打印导入的java库? [英] How to print imported java libraries?
本文介绍了如何打印导入的java库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在Java代码中打印已导入的库,并在执行期间可用?
Is there a way to print within a Java Code the libraries that has been imported, and available during the execution?
例如:
import javax.swing.JFrame;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//some code
}
}
I需要打印 javax.swing.JFrame
。
推荐答案
如果需要你的源代码中使用的实际导入(而不是使用字节码中的信息),你可以使用一个名为 QDox 的库来解析它您的源代码,并可以获得您使用的导入列表:
If you need the actual imports used in your source code (rather than using the information in the bytecode), you can use a library called QDox which will parse your source code and can get a list of the imports you use:
Main.java
Main.java
import com.thoughtworks.qdox.JavaDocBuilder;
import javax.swing.JFrame;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JavaDocBuilder java = new JavaDocBuilder();
java.addSourceTree(new java.io.File("."));
for (String i : java.getClassByName("Main").getSource().getImports()) {
System.out.println(i);
}
}
}
编译并运行:
# If you don't have wget, just download the QDox jar by hand
wget -U "" http://repo1.maven.org/maven2/com/thoughtworks/qdox/qdox/1.12/qdox-1.12.jar
javac -classpath qdox-1.12.jar Main.java
java -classpath qdox-1.12.jar:. Main
输出为:
com.thoughtworks.qdox.JavaDocBuilder
javax.swing.JFrame
这篇关于如何打印导入的java库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文