This content has been marked as final. Show 9 replies
There are no files. All you have are a few entry sets in a JAR file that become files when you extract and write them, so you will never get a File object directly from a JAR. You'd have to use the JarFile class for that and work through the entries.
that's great, thank you I will look into that.
Hi I've been looking everywhere and trying lots of things to try and get access to the jar file while I'm actually running inside of it and I can't find a way. The code below needs a location of the jar file but I can't find out how to get this information while i'm running inside the jar. I'm using java web start so the application will be loaded onto a user machine and could be run from a variation of places.
JarFile jf = new JarFile( f );
(need to add a comment to mark as unanswered)
fitz29 wrote:You have an interesting understanding of stuff. You're not running "in a JAR file". You're running in RAM with resources read from the JAR.
Hi I've been looking everywhere and trying lots of things to try and get access to the jar file while I'm actually running inside of it and I can't find a way.
The code below needs a location of the jar file but I can't find out how to get this information while i'm running inside the jar.The information won't really be available anyway, because your JAR ceases to exist in the case of Java Web Start. If you ever had a look at the JWS cache, it'll contain a bunch of JARs, but none of them is the roiginal one.
I'm using java web start so the application will be loaded onto a user machine and could be run from a variation of places.Then you're pretty much SOL. With a regular JAR, you could have added some "anchor" resource which you know, get its URL by getResource() and then parse the URL string for the JAR's location. With JWS mangling the JARs, this may not work.
You'll probably have to provide a list.
I'm sorry, I didn't quite think of this reading your first post.
Yes I've tried to getResource and then parse the location but unforunately it returns the remote location of the jar in the file something along the lines of http://www.myurl.com/myJar.jar!/Images/myImage.jpg. Unfortunately this hasn't seemed to help at all, however I'm still silently hopeful there's something out there as the getResource() can navigate the jar then surely there must be a way of doing it, and hopefully in a less restrictive way.
Hm, I wasn't aware that JWS isn't necessarily downloading stuff. Maybe for online-only apps... it's been years since I last used it.
Sure getResource can still load resources from there. See UrlClassLoader. Which won't immediately help you, unless you look at its sources for the resource-finding mechanism.
I think that you are right and that it doesn't actually go back to the url location to retrieve the file. I'd hazard a guess that it's more of a location label for the files of the jar, but I will keep on looking into it.
Cross posted and answered in the Java Archive (JAR) Files forum.
Cross posting is rude.