获取当前 JNLP 信息

发布于 2024-10-16 20:36:26 字数 168 浏览 6 评论 0原文

我正在从 jnlp 文件运行一个应用程序,该文件包含有用的信息,例如供应商、描述和其他字段。

在运行时获取此数据以构建“关于”对话框的最合理方法是什么?

有没有办法检测应用程序是否已在没有 Java Web Start 的情况下启动?

感谢您的帮助。

皮埃尔

I'm running an application from a jnlp file that contains useful information such as the vendor, a description, and other field.

What is the most reasonable way to get this data at Runtime in order to build an "About" dialog ?

Is there a way to detect that the application has been launched without Java Web Start ?

Thanks for your help.

Pierre

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2024-10-23 20:36:26

有多种策略可以实现预期目标。我不会重新讨论已经提到的内容,而是概述更多内容。


1)
信息可以放置在档案清单中。可以使用 java.lang.Package 的方法检索它 类。

String title = pckg.getImplementationTitle();
String vendor = pckg.getImplementationVendor();
String version = pckg.getImplementationVersion();

Package 类还能够识别所有已加载包。

Package[] package = Package.getPackages();

迭代查找您的包,您可以获得当前加载的所有包的列表。

将信息放入清单的最佳方法是使用 Ant 或一些类似的构建工具。这样就可以将版本设置为日期 - 很容易完成。


2) 将属性添加到 JNLP 的资源部分。

<resources>
    .. 
    <property name="jnlp.href" value="${href}" />
    ..
</resources>

顺便说一句 - 使用 ${href} 的目的是表示与 JNLP href 属性使用的字符串完全相同。

使用 BasicService.getCodeBase() 方法获取代码库。
使用 .. 形成 JNLP 文件的 URL。

URL urlToJnlp = new URL(
    basicService.getCodeBase(),
    System.getProperty("jnlp.href") );

加载 JNLP 文件并使用 J2SE 的众多 XML API 之一对其进行解析。 (如果它没有加载到 J2SE 的 XML API 中,则强烈表明它无效或格式错误 - 并且应该使用诸如 JaNeLA。)

一旦加载并解析,即可获取基本信息&提出。

There are various strategies to achieving the desired goal. I will not revisit those already mentioned, but instead outline several more.


1)
Information can be placed in the manifest of an archive. It can be retrieved using methods of the java.lang.Package class.

String title = pckg.getImplementationTitle();
String vendor = pckg.getImplementationVendor();
String version = pckg.getImplementationVersion();

The Package class also has the ability to identify all loaded packages.

Package[] package = Package.getPackages();

Iterate that looking for your packages and you can gain a list of all the packages currently loaded.

The best way to put the information into the manifests is using Ant or some similar build tool. That way the version can be set to the date - easy done.


2) Add a property to the resources section of the JNLP.

<resources>
    .. 
    <property name="jnlp.href" value="${href}" />
    ..
</resources>

BTW - that use of ${href} is intended to mean the exact same string used as the JNLP href attribute.

Use the BasicService.getCodeBase() method to obtain the codebase.
Form an URL to the JNLP file using ..

URL urlToJnlp = new URL(
    basicService.getCodeBase(),
    System.getProperty("jnlp.href") );

Load the JNLP file and parse it using one of the plethora of XML APIs of the J2SE. (And if it does not load in the XML APIs of the J2SE, it strongly indicates it is invalid or malformed - and should be checked using a tool such as JaNeLA.)

Once it is loaded and parsed, the basic information can be obtained & presented.

三生殊途 2024-10-23 20:36:26

您可以通过检查 jnlp 服务的可用性来检测应用程序是否是使用 webstart 启动的。类似于:

public boolean launchedByJNLP(){
    try {
        ServiceManager.lookup("javax.jnlp.BasicService");
    } catch (UnavailableServiceException e) {
        return false;
    }

    return true;
}

至于获取“关于”对话框的 jnlp 信息,我认为最好的解决方案是将“关于”对话框中所需的任何信息包含在与应用程序一起打包的单独属性文件中。

You can detect if the application was launched using webstart by checking on the availability of the jnlp services. Something like:

public boolean launchedByJNLP(){
    try {
        ServiceManager.lookup("javax.jnlp.BasicService");
    } catch (UnavailableServiceException e) {
        return false;
    }

    return true;
}

As for getting jnlp information for an About dialog, I think your best solution is to include whatever information you want in your about dialog in a separate properties file packaged with your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文