JNLP Webstart Launch Issue

2019-09-07 09:57发布

问题:

I have a requirement to dynamically extract the content of a Jar file to a local directory. Remaining part of application will use these content. Everything working well in my eclipse development environment. However following peace of code returns null when it comes into JNLP launch.

InputStream stream =  VLCLibManager.class.getClass().getClassLoader().getSystemResourceAsStream("XXX.jar");

I already did following :

  1. Manifest file of JAR that contains VLCLibManager.class updated with proper class-path entries
  2. My XXX.jar is placed under /lib directory of JNLP. It's getting downloaded correctly
  3. Have the entry (jar href="lib/XXX.jar"/>>) in XYZ.jnlp file

Any help appreciated as I'm stucked with this issue for the past few days.

回答1:

Finally I resolved the issue. Thought of publishing here as it would help others who face similar issue.

I did below :

  1. I packed resources that I wanted as a Zip file and placed into /resources directory of my maven project

  2. Maven compiler plugin packs this zip file along with resultant jar.

  3. So I can load the zip file to my java code using

    YourClass.class.getResourceAsStream("/XXXX.zip")

This loads resources to java program. You can unzip as you wanted and use it whereever needed