Java Jar File Find getJarLocation()

Here you can find the source of getJarLocation()

Description

Gets the path of the running jar file

License

Open Source License

Declaration

public static String getJarLocation() throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URISyntaxException;

public class Main {
    /**/*from ww w  .ja  v  a2s .c  o m*/
     * Gets the path of the running jar file
     */
    public static String getJarLocation() throws URISyntaxException {
        String path = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();

        if (path.endsWith(".jar"))
            path = path.substring(0, path.lastIndexOf("/"));

        return path;
    }
}

Related

  1. getJarFile(Class clazz)
  2. getJarFile(final ClassLoader loader)
  3. getJarFile(String classPath)
  4. getJarFileByResourceName(Class clazz, String resourceName)
  5. getJarFolder(Class clazz)
  6. getJarLocation(Class classFromJar)
  7. getJarLocation(Class clazz)
  8. getJarLocation(final Class cClass)
  9. getJarManifest(File file)