⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e067. determining from where a class was loaded.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -