JarUrl

try {
    // Create a URL that refers to a jar file on the net
    URL url = new URL("jar:http://hostname/my.jar!/");

    // Create a URL that refers to a jar file in the file system
    url = new URL("jar:file:/c:/almanac/my.jar!/");

    // Get the jar file
    JarURLConnection conn = (JarURLConnection)url.openConnection();
    JarFile jarfile = conn.getJarFile();

    // When no entry is specified on the URL, the entry name is null
    String entryName = conn.getEntryName();  // null


    // Create a URL that refers to an entry in the jar file
    url = new URL("jar:file:/c:/almanac/my.jar!/com/mycompany/MyClass.class");

    // Get the jar file
    conn = (JarURLConnection)url.openConnection();
    jarfile = conn.getJarFile();

    // Get the entry name; it should be the same as specified on URL
    entryName = conn.getEntryName();

    // Get the jar entry
    JarEntry jarEntry = conn.getJarEntry();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.