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) ie 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:
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
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).
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.