e067. determining from where a class was loaded.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 28 行
TXT
28 行
// Get the location of this class
Class cls = this.getClass();
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation(); // file:/c:/almanac14/examples/
It is not possible to determine the location of classes loaded by the system class loader in the same way since the class' code source is null. The only other method is to use the -verbose option on the java command. This causes the Java virtual machine to print a message every time a class is loaded.
> java -verbose MyApp
Here's a sample of the output:
[Opened c:\jdk1.4\jre\lib\rt.jar]
[Opened c:\jdk1.4\jre\lib\sunrsasign.jar]
[Opened c:\jdk1.4\jre\lib\jsse.jar]
[Opened c:\jdk1.4\jre\lib\jce.jar]
[Opened c:\jdk1.4\jre\lib\charsets.jar]
[Loaded java.lang.Object from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.io.Serializable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Comparable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.String from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Class from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Cloneable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.ClassLoader from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.System from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Throwable from c:\jdk1.4\jre\lib\rt.jar]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?