Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 332
Andez Avatar asked Jun 16 '11 12:06

Andez


2 Answers

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).

like image 154
Waldheinz Avatar answered Nov 16 '22 09:11

Waldheinz


Perhaps javax.jnlp.BasicService.getCodeBase is what you're looking for.

Returns the codebase for the application. The codebase is either specified directly in the JNLP file, or it is the location of the JAR file containing the main class of the application.

Returns:
     a URL with the codebase of the application

(The BasicService "mimics loosely the AppletContext functionality" which provides the getDocumentBase() you're referring to.)

like image 29
aioobe Avatar answered Nov 16 '22 10:11

aioobe