通过 JNLP 的 Java Applet:System.Properties 未“设置”
我已经有很多年没有在 Java 中工作了(这是我的借口)。
我正在尝试将 Java Swing UI 作为 Applet 启动(以前通过 Web Start 完成)。
我修改了 jnlp 文件以反映我所知道的小程序所需的更改(例如使用 applet-desc 而不是 application-desc)。
在 jnlp 文件的
标记内,我们设置系统属性,如下所示:
<property name="java.security.auth.login.config" value="$$context/app/auth.conf"/>
在主类的 init 方法中,我们尝试读取其中一些系统属性,但总是得到“null”作为价值。
有人知道为什么系统属性不“粘着”吗?
可能相关的奇怪之处:我将 Java 设置为在运行时打开控制台。当我使用此小程序加载页面时,控制台窗口会打开两次,两个窗口都显示加载 jnlp 的详细信息,但只有一个窗口继续完整的应用程序加载。
更新:
这是 jnlp 文件:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" >
<information>
<title>app</title>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" java-vm-args="-Xms128m -Xmx1024m -Xss1m"/>
<property name="java.naming.factory.initial" value="org.jboss.naming.HttpNamingContextFactory"/>
<property name="java.naming.factory.url.pkgs" value="org.jboss.naming:org.jnp.interfaces"/>
<property name="java.naming.provider.url" value="$$context/invoker/JNDIFactory"/>
<property name="java.security.policy" value="$$context/app/server.policy"/>
<property name="java.security.auth.login.config" value="$$context/app/auth.conf"/>
<property name="login.context" value="client-login"/>
<property name="jndi.port" value="1099"/>
<property name="service.impl" value="Remote"/>
<property name="polling" value="true"/>
<jar href="cglib-2.1.3.jar"/>
<jar href="com.jdas.apps.binmgmt.gui.jar" main="true"/>
<jar href="commons-beanutils.jar"/>
<jar href="commons-collections-2.1.1.jar"/>
<jar href="commons-javaflow.jar"/>
<jar href="commons-lang.jar"/>
<jar href="commons-logging.jar"/>
<jar href="ecs-1.4.1.jar"/>
<jar href="hibernate3.jar"/>
<jar href="itext-1.01.jar"/>
<jar href="jade-5.2.3_AGRIS_PATCH.jar"/>
<jar href="jbossall-client.jar"/>
<jar href="jboss-j2ee.jar"/>
<jar href="jcalendar-1.1.4-agris.jar"/>
<jar href="jhall-3.1.3.jar"/>
<jar href="looks-all-1.1.jar"/>
<jar href="odmg-3.0.jar"/>
<jar href="pvjdbc2.jar"/>
<jar href="swing-layout-1.0.jar"/>
<extension name="additional" href="unsigned.jnlp"/>
</resources>
<applet-desc main-class="com.jdas.apps.binmgmt.gui.main.BinManagementApp" name="binMgmt" width="1024" height="768" >
</applet-desc>
</jnlp>
It is years since I have worked in Java (that's my excuse).
I am trying to launch a Java Swing UI as an Applet (previously done via Web Start).
I have modified the jnlp file to reflect the changes that I know are necessary for an applet (e.g. using applet-desc instead of application-desc).
Inside the <resources>
tag in the jnlp file we set system properties like this:
<property name="java.security.auth.login.config" value="$context/app/auth.conf"/>
In the init method of the main class we try to read some of these system properties and always get "null" as the value.
Does anyone have any ideas why the system properties aren't "sticking"?
Possibly related strangeness: I have Java set to open the console when something runs. When I load the page with this applet, the console windows opens TWICE, both windows showing the details of loading the jnlp, but only one window continues with the full app load.
UPDATE:
Here is the jnlp file:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" >
<information>
<title>app</title>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" java-vm-args="-Xms128m -Xmx1024m -Xss1m"/>
<property name="java.naming.factory.initial" value="org.jboss.naming.HttpNamingContextFactory"/>
<property name="java.naming.factory.url.pkgs" value="org.jboss.naming:org.jnp.interfaces"/>
<property name="java.naming.provider.url" value="$context/invoker/JNDIFactory"/>
<property name="java.security.policy" value="$context/app/server.policy"/>
<property name="java.security.auth.login.config" value="$context/app/auth.conf"/>
<property name="login.context" value="client-login"/>
<property name="jndi.port" value="1099"/>
<property name="service.impl" value="Remote"/>
<property name="polling" value="true"/>
<jar href="cglib-2.1.3.jar"/>
<jar href="com.jdas.apps.binmgmt.gui.jar" main="true"/>
<jar href="commons-beanutils.jar"/>
<jar href="commons-collections-2.1.1.jar"/>
<jar href="commons-javaflow.jar"/>
<jar href="commons-lang.jar"/>
<jar href="commons-logging.jar"/>
<jar href="ecs-1.4.1.jar"/>
<jar href="hibernate3.jar"/>
<jar href="itext-1.01.jar"/>
<jar href="jade-5.2.3_AGRIS_PATCH.jar"/>
<jar href="jbossall-client.jar"/>
<jar href="jboss-j2ee.jar"/>
<jar href="jcalendar-1.1.4-agris.jar"/>
<jar href="jhall-3.1.3.jar"/>
<jar href="looks-all-1.1.jar"/>
<jar href="odmg-3.0.jar"/>
<jar href="pvjdbc2.jar"/>
<jar href="swing-layout-1.0.jar"/>
<extension name="additional" href="unsigned.jnlp"/>
</resources>
<applet-desc main-class="com.jdas.apps.binmgmt.gui.main.BinManagementApp" name="binMgmt" width="1024" height="768" >
</applet-desc>
</jnlp>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要对 JNLP 文件进行签名才能设置系统属性(具有特殊 豁免)。查看您尝试设置的一些属性!
要签署 JNLP 文件,请在签署 jar 之前将逐字节副本(最好坚持 US-ASCII(!))放入 JNLP-INF/APPLICATION.JNLP 中。
You will need to sign the JNLP file in order to set system properties (other than those properties that have special exemption). Look at some of those properties you are trying to set!
To sign a JNLP file, put a byte-for-byte copy (best to stick to US-ASCII(!)) in JNLP-INF/APPLICATION.JNLP before signing the jar.
刚花了 2 天尝试解决这个问题,尝试对 jar 和其他文件进行签名...然后我找到了似乎非常简单并且工作正常的解决方案:
我 *放置了一个 jndi.properties 文件我的 JRE-home-director 中的以下内容*y (jre7/lib):
我在从 Java 1.6 更新到 Java 1.7 时遇到了这个问题...
Just spent 2 days trying to fix this problem, trying to sign jars and other files...and then I found the solution which seems to be very simple and is working fine:
I *put a jndi.properties-file with the following content in my JRE-home-director*y (jre7/lib):
I had this problem when updating from Java 1.6 to Java 1.7...