简体   繁体   English

Java Web Start getDocumentBase

[英]Java Web Start getDocumentBase

I am experimenting with Java Web Start. 我正在试验Java Web Start。

I have just written a basic JApplet which has a method on the Applet class called getDocumentBase() . 我刚刚编写了一个基本的JApplet ,它在Applet类上有一个名为getDocumentBase() This returns the full URL to the location the Applet is running (under Tomcat) ie http://myserver:8080/myapp/whateverapplet.jar . 这会将完整的URL返回到Applet运行的位置(在Tomcat下),即http:// myserver:8080 / myapp / whateverapplet.jar

However, I am looking for something similar with a web start application. 但是,我正在寻找与Web启动应用程序类似的东西。 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: 就运行的位置而言,我的意思是如果我从我想要的JNLP文件运行Web启动:

http://myserver:8080/myapp HTTP:// MYSERVER:8080 / MYAPP

If I run the JAR from a folder on the network I want: 如果我从网络上的文件夹运行JAR我想要:

\\\\server\\myapp \\\\服务器\\ MYAPP

Or if I run the JAR from a folder on my machine I want: 或者,如果我从我的机器上的文件夹运行JAR,我想:

D:\\myapp d:\\ MYAPP

End Edit 结束编辑

I guess you want to get the code base URL from within your running application? 我想你想从正在运行的应用程序中获取代码库URL? 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). 请注意,您必须依赖JNLP API来编译此代码(对于BasicService类)。

Perhaps javax.jnlp.BasicService.getCodeBase is what you're looking for. 也许你正在寻找javax.jnlp.BasicService.getCodeBase

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. 代码库可以直接在JNLP文件中指定,也可以是包含应用程序主类的JAR文件的位置。

Returns: 返回:
a URL with the codebase of the application 带有应用程序代码库的URL

(The BasicService " mimics loosely the AppletContext functionality " which provides the getDocumentBase() you're referring to.) BasicService松散地模仿AppletContext功能 ”,它提供了你所指的getDocumentBase() 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM