Here you can find the source of getJarPathOf(Class> classObject)
Parameter | Description |
---|---|
classObject | The class object to check |
public static String getJarPathOf(Class<?> classObject)
//package com.java2s; /*/*from ww w . jav a2 s. c o m*/ * Copyright (C) 2016 Sebastian Hjelm * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. */ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class Main { /** * Returns the path to the jar-file the specified class object resides in. This * only works if the specified class is within a jar-file. * @param classObject The class object to check * @return The jar-file the specified class object resides in */ public static String getJarPathOf(Class<?> classObject) { try { String path = URLDecoder .decode(classObject.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"); return path; } catch (UnsupportedEncodingException e) { } return ""; } }