Web Start unable to load external driver
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>
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
<jar href="myLibrary.jar"/>
However for a resource that is signed by somebody else your entry looks like so
<extension href="Driver.jnlp" name="Driver" version=""/>
And it needs its own JNLP file
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="{yourcodebase}" href="Driver.jnlp">
<information>
<title>Driver</title>
<vendor>Driver Corporation</vendor>
</information>
<resources>
<jar href="lib/TheExternalDriver.jar"/>
</resources>
<security>
<all-permissions/>
</security>
<component-desc/>
</jnlp>
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.
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.
精彩评论