String path = ClassA.class.getProtectionDomain().getCodeSource().getLocation.getPath();ClassA是已经被ClassLoader加载的类,path将取得ClassA所在的路径。