Java Class Path getFullPathOfClass(Class cls)

Here you can find the source of getFullPathOfClass(Class cls)

Description

get Full Path Of Class

License

CDDL license

Declaration

public static String getFullPathOfClass(Class cls) 

Method Source Code

//package com.java2s;
/*//from  www  .  ja v  a2 s  .  c  o  m
 Copyright (c) 2013 eBay, Inc.
 This program is licensed under the terms of the eBay Common Development and
 Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
 thereof released by eBay.  The then-current version of the License can be found 
 at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
 is under the eBay SDK ../docs directory.
 */

import java.net.URL;

public class Main {
    public static String getFullPathOfClass(Class cls) {
        URL url = cls.getProtectionDomain().getCodeSource().getLocation();
        String path = url.getPath();

        String[] dirs = cls.getName().split("\\.");

        for (int i = 0; i < dirs.length - 1; i++)
            path += dirs[i] + "/";

        return path;
    }
}

Related

  1. getClassFilePath(final Class cls)
  2. getClassFilePath(String package_name, String class_name)
  3. getClassNameByFile(String filePath, List className, boolean childPackage)
  4. getDirectoryPath(Class owner)
  5. getFile(Class base, String path)
  6. getFullpathRessources(Class c, String ressource)
  7. getInputStream(Class cls, String path)
  8. getPath(Class tClass)
  9. getPath(final String aPath, final Class aClass)