10

Try as I might, I can't get a JNLP file to run locally (via a double-click). It seems to be an issue of locating a jar file, even when I specify it relative to the jnlp file. I get the following error:

The field <jar>href has an invalid value: helloworld.jar

This happens even when the JNLP file is in the same folder as helloworld.jar. I've done searches and this is a consistent problem especially for people who want to package an application on a CD and use JNLP. The only Sun-provided "solution" is the ability to specify the codebase via command line, but that doesn't really help much. I don't understand why they don't assume or allow the codebase to be "." or "file://." - I tried these sorts of things in the codebase parameter of the jnlp tag (inside the file) and nothing worked.


It is extremely convenient for me to use a JNLP file because I don't need to worry about platform detection, native libraries, or even the main JOGL jar files; I simply include this line and everything is done for me:

<extension name="JOGL" href="http://download.java.net/media/jogl/builds/archive/jsr-231-2.0-beta10/webstart/jogl-all-awt.jnlp" />

I'm hoping to find something that can do the same sort of thing. If not, I can manually (or with Ant) grab the JOGL jar files, it's not a big deal; just one of those things that JNLP does for me and I'm really going to miss.


What is the best alternative to JNLP files, for me to use locally (i.e. double-click to run)? Is there anything so elegant or do I just need to write a shell script for Linux, a batch file for Windows, and have Ant detect and download the appropriate JOGL jars?

Ricket
  • 33,368
  • 30
  • 112
  • 143
  • If anyone else out there has a better answer than the ones below, please speak up! I'd still love to hear if it's possible to run JNLP files from the local filesystem. However, after some research I've decided it to be impossible and have since gone with my own suggestion; a pair of scripts (run.bat and run.sh), and my Ant script uses condition tags and downloads & unpacks the correct JOGL jar. I'll be submitting an answer containing the Ant code shortly. – Ricket Jan 13 '10 at 15:35

5 Answers5

22

I've used a .jnlp file like this to launch Java Web Start software locally

  1. specify the code base like so: <jnlp spec="1.0+" codebase="file://localhost/X:/path/to/jnlp/" href="software.jnlp">

  2. list resources with relative paths: <resources> <jar href="lib/software.jar" main="true" /> <jar href="lib/softwareLibrary.jar" main="true" /> ... </resources>

  3. and finally tell Web Start where it can find the software entry point inside the jar marked with main="true": <application-desc main-class="com.example.Main" />

The only thing you need to change when deploying remotely is the codebase parameter.

Riku L
  • 367
  • 3
  • 9
  • 1
    And this doesn't require some sort of web server or file server running on localhost to parse that path? – Ricket Mar 10 '10 at 15:57
  • No, but the localhost part is still required. Doesn't work without it, works if you put it in. Took me half a day to figure out :-) – Riku L Mar 11 '10 at 07:33
  • That's really cool. I wish you were around back in January when I was messing with this. Since this is the answer I was looking for, I'm switching the accepted answer to you. :) – Ricket Mar 11 '10 at 13:18
  • 4
    Also, you can launch locally by leaving out the `codebase` attribute. It's now optional: http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html – The Alchemist Mar 29 '11 at 15:47
  • Time to replace all my launch shell scripts with JNLP. So much neater with platform detection and everything. – whatnick Mar 30 '11 at 01:24
  • 2
    For me this only worked when I changed the code base to: file:///X:/path/to/jnlp/ (so three forward slashes, then the drive letter) – Adriaan Koster Jan 06 '17 at 15:40
  • Like @AdriaanKoster, this only worked when I used file:///X:/blah/blah/blah, otherwise it was giving me an error about an "authority in the URI". – Amber Feb 13 '19 at 20:02
4

Just remove the attributes codebase and href from jnlp tag.

<jnlp spec="1.0+">

This is supported since java 1.6u18.

Daniel De León
  • 13,196
  • 5
  • 87
  • 72
2

The JNLP system was improved with Java 6 update 10 (a while back) but it is still quite hard to debug (enabling full tracing in the Java Console, and stepping through the javaws source code.

In your situation I would go the extra mile and get it to work. Perhaps you would provide a full JNLP-file showing the problem?

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
1

Use a manifest for your jar. There you can define the main class to start and the required libraries. See the Main-class and Class-path arguments in the manifest specification.

Daniel Hiller
  • 3,415
  • 3
  • 23
  • 33
0

JNLP is designed for network launching (specifically http(s)) and without a network the Java implementation must get really confused. Even mature projects like eclipse stick with the .sh,.bat option.

whatnick
  • 5,400
  • 3
  • 19
  • 35
  • Not necessarily... NetBeans has a local JNLP launch option out of the box. Also, if you look at @Shrike's comment, you can see that local department isn't that difficult. – The Alchemist Mar 29 '11 at 15:46