Here you can find the source of getClassFilePath(Class> clazz)
Parameter | Description |
---|---|
clazz | a parameter |
public static String getClassFilePath(Class<?> clazz)
//package com.java2s; //License from project: LGPL import java.io.File; import java.net.URL; import org.eclipse.core.runtime.FileLocator; public class Main { /**//from w ww. j a v a 2 s . co m * Gets the path to a class file * * @param clazz * @return */ public static String getClassFilePath(Class<?> clazz) { String className = clazz.getName(); String resourceName = "/" + className.replace('.', '/') + ".class"; // get a URL so we can turn it into a file URL classURL = clazz.getResource(resourceName); if (classURL != null) { try { if (classURL.toString().contains("bundle")) { classURL = FileLocator.resolve(classURL); } // get the file, so we can get a full path reference File classFile = new File(classURL.getFile()); // now we have the full file path String classPathBase = classFile.getAbsolutePath(); return classPathBase; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return className; } }