Searching...
Saturday, 30 November 2013

How to get class loaded location in Java

00:09

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/


0 comments: