我有需要外部配置的网络启动应用程序。配置必须是外部的,因为它将由我们的客户手动更改。我考虑使用此配置添加另一个罐子。应用程序已签名,并且不能将我们的密钥提供给客户。我倾向于将此文件放置为可从网络服务器访问的位置。
如何从 webstart 应用程序内部检索代码库 url,或者有没有办法配置 webstart jnlp 文件以将 jar 以外的其他文件添加到类路径?
我使用 Maven 来完成构建,如果这是一个线索的话。
任何其他想法都是可以接受的。
I have webstart application that needs external configuration. Configuration must be external, because it will be changed manually by our customer. I considered adding another jar with this configuration. Application is signed and giving our keys to customer is not a option. I'm leaning towards placing this file to be accessible from web server.
How retrive codebase url from webstart application inside or is there a way to configure webstart jnlp file to add other file than jar to classpath?
I use maven for complete build, if it is a clue.
Any others ideas are acceptable.
发布评论
评论(4)
您可以使用
BasicService.getCodeBase
。You can get the codebase with
BasicService.getCodeBase
.您可以使用 Java Preferences API存储外部配置数据。这对于该人的机器来说是本地的。在 Windows 上,它使用注册表,在 Unix 上使用经典的“.xyz”文件。
您最好在您的应用程序上有一些 UI 来操作此配置(将用户发送到 RegEdit 并不是一件好事),但它不必是任何光荣的事情。名称/值对编辑器就可以解决这个问题。并使用合理的默认值来启动“未配置”的应用程序。
You can use the Java Preferences API to store external configuration data. This will be local to the persons machine. On Windows, it uses the Registry, on Unix is uses classic ".xyz" files.
You would be best having some UI on your app for manipulating this configuration (sending users to RegEdit isn't really a nice thing), but it doesn't have to be anything glorious. A Name/Value pair editor will do the trick. And use reasonable defaults for starting up an "unconfigured" app.
如果您使用 JNLP 下载 Servlet 您可以将 $$codebase 宏作为系统属性传递到您的应用程序中,这将允许访问代码库 URL。
在我们的 webstart 应用程序中,配置使用 SQL 存储到服务器,但这对于您的需求来说可能有点繁重。
If you use the JNLP Download Servlet you can pass the $$codebase macro into your application as a system property and this will give access to the codebase URL.
In our webstart application configuration is stored to the server using SQL but that could be a bit heavyweight for your needs.
在这里查看 jnlp 语法参考:
http://java.sun.com/ j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html
对您来说重要的一点是“Resources”标记:
在上面的示例中,SwingSet2.jar 添加到类路径中。类路径上需要更多 jar 吗?添加另一个 jar 资源
我在代码库方面遇到了完全相同的问题。我最终使用了一个 JnlpServlet (你必须用 google 搜索它。我只能发布一个超链接 :( ),以便在提供 jnlp 文件时自动包含正确的代码库,然后添加
到资源部分。
Check out the jnlp syntax reference here:
http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html
The important bit for you is the "Resources" tag:
In the above example, SwingSet2.jar is added to the classpath. Need more jars on the classpath? Add another jar resource
I had exactly the same trouble with codebase. I ended up using a JnlpServlet (You'll have to google it.. I can only post one hyperlink :( ) to automatically include the correct codebase when it serves up the jnlp file, then add
to the resources section.