Getting a Jar File Using a URL

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) { }

Comments

20 Jul 2010 - 12:46am by Virtualwarp (not verified)

I just came across this place to look if a jarurl nesting another url is really valid. In my application I created a jarurl as above, but the result of the invocation of getJarFile on the JarURLConnection is always "null". The code above doesn't make sense for me, why are the http-jarurl at the beginning and the jarFile-variable never used? The title is a little bit confusing, the code is more about how to get an JarEntry and working with jar files. The JarFile object itself is only returned if the url refers to a file on the local filesystem. Event with a file-url it doesn't work on my machine (windows 7), so I have to invoke getJarFileURL and convert it by myself to an JarFile, if it is a file-url.

21 Jul 2010 - 11:32am by Scott (not verified)

My issue is that once I have done this, what do I then do with the Jar Entry. I can't seem to see the purpose of this, becuase now I can't access the file or anything.

Also, your captchas are impossible.

3 Sep 2010 - 12:44am by tudor watches (not verified)

Gold, who initiated the lawsuit womens Nike jacket in 2003 on behalf of nike walking shoes her children, who were minors mens swiss watches at the time, insisted that dolce and gabbana watch in addition to four legal boots louboutin contracts signed promising living expenses Nike clothing and college educations for the iwc watches children, Bren had also verbally Nike shox shoes vowed to be a part Dior rings of their lives.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.