Código: Seleccionar todo


import java.io.File;
import java.net.URISyntaxException;
/**
 *
 * @author adwind
 * Clase que nos sirve para devolver la ruta completa de nuestro jar.
 * Similar a lo que se hace en vb. para obtener el full-path del mismo exe.
 */
public class JarPath {

    private String path = null;

    public JarPath() {
        try {
            File server = new File(JarPath.class.getProtectionDomain().getCodeSource().getLocation().toURI());
            path=server.getAbsolutePath();
        } catch (URISyntaxException ex) {
        }
    }

    public String getJarPath() {
        return path;
    }
    
    public static void main(String[] args) {
        JarPath m=new JarPath();
        System.out.println(m.getJarPath());
    }
}

Responder

Volver a “Fuentes”