How to get class loaded location in Java

Example

package com.pretech;
import java.security.CodeSource;
public class ClassLoadLocation {
	public static void main(String[] args) {
		Class<ClassLoadLocation> clazz = ClassLoadLocation.class;
		CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
		System.out.println(clazz.getName()+ " class is loaded from : " + codeSource.getLocation());
	}
}

Output



com.pretech.ClassLoadLocation class is loaded from : file:/D:/Projects/stsworkspace/core-java/target/classes/


No comments:

Post a Comment

Confusion Matrix + Precision/Recall (Super Simple, With Examples)

  Confusion Matrix + Precision/Recall (Super Simple, With Examples) 1) Binary Classification Setup Binary classification means the model p...

Featured Posts