// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import org.apache.xml.serialize.XMLSerializer;

public class PathTest {
    private String getPath(Class cls) {
        String cn = cls.getName();
        String rn = cn.replace('.', '/') + ".class";
        String path = getClass().getClassLoader().getResource(rn).getPath();
        int ix = path.indexOf("!");
        if(ix >= 0) {
            return path.substring(0, ix);
        } else {
            return path;
        }
    }
    public static void main(String[] args) {
        PathTest pt = new PathTest();
        System.out.println(pt.getPath(PathTest.class));
        System.out.println(pt.getPath(String.class));
        System.out.println(pt.getPath(XMLSerializer.class));
    }
}
