Andez Andez - 4 months ago 47
Java Question

Java Web Start getDocumentBase

I am experimenting with Java Web Start.

I have just written a basic

which has a method on the
class called
. This returns the full
to the location the
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?


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


If I run the JAR from a folder on the network I want:


Or if I run the JAR from a folder on my machine I want:


End Edit

Answer Source

I guess you want to get the code base URL from within your running application? If this is the case, you can use this snippet:

final BasicService bs = (BasicService) ServiceManager.lookup(
final URL codeBase = bs.getCodeBase();

Note that you'll have to depend on the JNLP API to compile this code (for the BasicService class).