Andez Andez - 2 months ago 28
Java Question

Java Web Start getDocumentBase

I am experimenting with Java Web Start.

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:

http://myserver:8080/myapp

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

\\server\myapp

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

D:\myapp

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(
    "javax.jnlp.BasicService");
final URL codeBase = bs.getCodeBase();

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