This content has been marked as final. Show 4 replies
No can do... except by nasty, slow, nefarious, ugly, devious, sloppy and not very clever means.
Search the CLASSPATH for the first occurence of your jar file... but FFS only do it once, and save the result.
Now why would want to do that anyway? To keep an updatable properties file in the same place as the jar? Not a good idea, that's why it's difficult... One thing I've learned about java is that: "if it's a fairly common problem and the solution is complicated it's because you're doing it wrong".
"Search the CLASSPATH for the first occurence of your jar file... but FFS only do it once, and save the result"
Cud ya elaborate that statement.
Also, the reason i wanna know is this : my jar file references all the images that it uses, thru a relative path(./a/b/c.....). So wen i simply double click the jar file, the relative path("./") gets replaced with the current workin directory(from user.dir) and fetching of images works perfectly. But if it is launched via html, the user.dir does not get set to the current working dirctory and as a result the jar file looks for its images in the default location which is the desktop. so it doesnt work
If the images are static (ie: they remain unchanged once released) then include the images in your jar file (with a "copy" target in ant) and access them via getResourceAsStream... see the help in your IDE, most of them have "a feature" to facilitate adding additional resources to jar files.
If the images aren't static, then one solution is to require the user to create a system environment variable specifying the directory which contains your jarfile... MYAPP_HOME=c:\program files\my\app
If you really need to find my.jar in the classpath then search the forums... I know there's a few posts with code for a recursive breadth-first directory search, coz I posted 'em (probably as corlettk)... I just can't recall the details, and you can do your own searching.