I have just written a basic JApplet which has a method on the Applet class called getDocumentBase(). This returns the full URL to the location the Applet is running (under Tomcat) i.e. http://myserver:8080/myapp/whateverapplet.jar.

However, I am looking for something similar with a web start application. I need to know where it is running. Is there anything that can give me this information?

EDIT

In terms of where it is running I mean if I run a web start from a JNLP file I want:

@Andrew - thanks for the example. I've tried it in my code and it works fine from a web start. Like I mentioned on the other answer by aioobe, I did try MyClass.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm‌​() which gave me the full path to the JAR file however I wanted to know the location.
–
AndezJun 16 '11 at 12:24

@aioobe - thanks for that. Thats works for me. However, I did the following code which gives me the full path to the JAR file without using BasicService. MyClass.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm‌​()
–
AndezJun 16 '11 at 12:21

@Andez: If that code (presumably running in a trusted app.) provides the location of the class files in the local file system, don't write anything there, and don't expect to find anything there that is not already on the run-time class-path of the app. Why exactly do you want this information? What feature is it that knowing that location brings to the application?
–
Andrew ThompsonJun 16 '11 at 12:29

@Andrew - we have an Images folder in the same location as our JAR file which the application will load at various points. These are not contained in a resource file as the idea is to allow customisation on site without recompiling a JAR file. new JButton( "Button 1", new ImageIcon( new URL(fullurl + "Images/add.png" ), "" ) ) works for me where fullurl is given by the URL.toString() from your example.
–
AndezJun 16 '11 at 12:48

If by "onsite" you mean the site from which this version of the app. is launched, then getCodeBase() as mentioned by aioobe is the way to go. If you mean "on the end user's desktop" then there is a better strategy to pursue (using the PersistenceService).
–
Andrew ThompsonJun 16 '11 at 13:32