Web Start 无法加载外部驱动程序
我有一个 Java 应用程序项目,它运行良好,直到我将其放入 Web 启动中。我的项目依赖外部库来处理串口和USB端口。
运行这个应用程序。在DOS命令中:
java -DPropLoc=Drivers.Properties -jar myprog.jar <args>
在Netbeans 6.7.1 JRE 1.6u21中,当选择WebStart作为项目配置时,我可以运行主项目,但无法加载驱动程序。 在项目属性中,我将 VM 选项设置为 -DPropLoc="Drivers.Properties
并且驱动程序依赖于此文件。 但如果我进行调试并逐步进行,它将加载驱动程序并且运行正常。
Web Start 启动时出现什么问题?
这是我加载驱动程序后遇到的错误:
Caught java.lang.NullPointerException: name can't be null while loading driver com.sun.comm.Win32Driver
javax.comm.NoSuchPortException at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105)
因为我不明白为什么在NB中一步步调试时会加载驱动程序。 但是通过按 F6 运行主项目,它不会加载驱动程序。 Debug 和 Run 之间的环境或 JVM 有什么区别。
下面是launch.jnlp文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="file:/C:/bit9prog/dev/NetBeansProjects/MyProg/dist/" href="launch.jnlp" spec="1.0+">
<information>
<title>MyProg</title>
<vendor></vendor>
<homepage href=""/>
<description>MyProg</description>
<description kind="short">MyProg</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+"/>
<property name="PropLoc" value="Drivers.Properties"/>
<jar eager="true" href="MyProg.jar" main="true"/>
<jar href="lib/comm.jar"/>
<jar href="lib/config.jar"/>
<jar href="lib/jakarta-regexp-1.4.jar"/>
<jar href="lib/log4j-1.2.14.jar"/>
<jar href="lib/swing-layout-1.0.jar"/>
<jar href="lib/trove.jar"/>
<jar href="lib/XmlUtil.jar"/>
</resources>
<application-desc main-class="MyProg">
<argument>r</argument>
<argument>.</argument>
</application-desc>
</jnlp>
I have a project as Java application, and it was running fine until I made it into web start. My project relies on external library to deal with serial port and USB port.
To run this app. in DOS command:
java -DPropLoc=Drivers.Properties -jar myprog.jar <args>
In Netbeans 6.7.1 JRE 1.6u21, When select WebStart as Project Configuration, I can run the the main project but it failed to load the driver.
In the Project Properties, I have the VM Option set to -DPropLoc="Drivers.Properties
and the driver relies on this file.
But if I do debug and with step by step, it will load the driver and thing run OK.
What is the problem with the web start launch?
This is the error I got after loading the driver:
Caught java.lang.NullPointerException: name can't be null while loading driver com.sun.comm.Win32Driver
javax.comm.NoSuchPortException at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105)
Since I don't understand why it loaded the driver when debugging in NB step by step.
But by running the main project by pressing F6, it won't load the driver. What is the difference of environment or JVM between Debug and Run.
Below is launch.jnlp
file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="file:/C:/bit9prog/dev/NetBeansProjects/MyProg/dist/" href="launch.jnlp" spec="1.0+">
<information>
<title>MyProg</title>
<vendor></vendor>
<homepage href=""/>
<description>MyProg</description>
<description kind="short">MyProg</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+"/>
<property name="PropLoc" value="Drivers.Properties"/>
<jar eager="true" href="MyProg.jar" main="true"/>
<jar href="lib/comm.jar"/>
<jar href="lib/config.jar"/>
<jar href="lib/jakarta-regexp-1.4.jar"/>
<jar href="lib/log4j-1.2.14.jar"/>
<jar href="lib/swing-layout-1.0.jar"/>
<jar href="lib/trove.jar"/>
<jar href="lib/XmlUtil.jar"/>
</resources>
<application-desc main-class="MyProg">
<argument>r</argument>
<argument>.</argument>
</application-desc>
</jnlp>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个安全问题。因为您的驱动程序正在进行本机访问,所以必须对其进行签名,如果驱动程序已经签名,则将其添加到 jnlp 文件的方式会略有不同。
例如,对于使用您的证书签名的内部库,则条目如下所示
但是对于由其他人签名的资源,您的条目如下所示
并且它需要自己的 JNLP 文件
This is a security issue. Because your driver is doing native access it has to be signed, and if the driver is already signed then the way that you add it to your jnlp file is slightly different.
For example with an internal library that is signed using your certificate then the entry look as follows
However for a resource that is signed by somebody else your entry looks like so
And it needs its own JNLP file
我相信 NetBeans 不会在同一当前目录中运行 WebStart 项目。
我建议您尝试提供驱动程序属性的绝对路径。
额外的测试是尝试检查您的程序在哪里运行,即 print
new File(".")
我希望这会有所帮助。
I believe that NetBeans does not run WebStart project in the same current directory.
I'd suggest you to try to supply absolute path to the driver properties.
Additional test is try to check where is your program running, i.e. print
new File(".")
I hope this will help.
感谢大家的帮助,最重要的是感谢安德鲁的有用反馈。
毕竟我能够创建使用 Webstart 运行的项目。我必须缩小规模以仅加载 USB 驱动程序,而不是同时加载 RS232 和 USB 驱动程序并导致该库发生冲突,但奇怪的是它作为标准 java 应用程序运行良好。由于我无法控制驱动程序的实现方式,因此我拥有的只是驱动程序提供商提供的 jar 文件。也许这是一个安全问题,但我对此表示怀疑,因为我能够自签名并在本地磁盘上运行。
Thanks everyone for the help and all-above thanks Andrew for useful feedback.
After all I was able to create my project running with Webstart. I have to scale down to load only USB driver, instead of loading both RS232 and USB drivers and have that library conflict, but strangely it was running fine as standard java application. Since I have no control of how the driver was implemented, all I have is a jar file from the driver provider. Maybe it's right that was a security issue, but I doubt about it, since I was able to selfsigned and run on local disk.