Elements of the JNLP File

In my last blog I attempted to run an applet using the following jnlp file::

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for ActiveMath -->

<jnlp spec="1.0+"
codebase="http://202.65.70.207/myweb/"
href="AMJ002.jnlp">
<information>
<title>Active Math Java Test</title>
<vendor>Softway Interactive Education</vendor>
<description>Active Math Java Test</description>
<homepage href="http://202.65.70.207/myweb/index.htm"/>
<description kind="short">ClickMeApp uses 1 custom class plus 1
standard one</description>
<offline-allowed/>>
</information>
<resources>
<jar href="ActiveMathJA002.jar"/>
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se"/>
</resources>
<application-desc main-class="AMJFormA002"/>
</jnlp>

The error message gave me a clue that perhaps I had not recorded the path to the Java bin file as an environmental variable. I had some trouble doing this on the old PIII I use for writing, but on the newer Core2 Duo, which I am using as a server, it was textbook doddle; computers and Windows installations degrade over time, and little things eventually don't work. Intermittent gremlins in Windows ought to be documented somewhere, but when some poor innocent experiences such a problem, and posts a question in a forum, it is amazing, the arrogance (illustrated here) with which some people respond.

I digress. The point is that after setting the path, I could run the jar file from my web directory, using the command prompt, but still not from a browser using the jnlp file. The error message was different, less informative, but still the application did not run. So I thought I'd continue the lesson by cross referencing my file with the elements table.

And of course the XML elements are not in the table. At the beginning of the tutorial we were given 4 screenshots to explain the simplest command, but now it is assumed we are all intimate with XML.

The first element to be explained, somewhat tautologously, is jnlp - the main xml element for a jnlp file. We are given a range of values for the attribute spec, including the wild card used in my file. The codebase is the URL for the folder hosting the jnlp file, and href gives the URL of the jnlp file relative to the codebase (which in this case is simply the filename).

Information is a containing element, which as the name suggests contains elements giving information about the application. I shall refrain from going through these as they are all pretty obvious, and do not seem essential to the running of the app.

Resources seems to be another containing element which: "Describes all the resources that are needed for an application". The first such contained in my file is jar, which: "Specifies a JAR file that is part of the application's classpath". The first attribute used in my file is href, which gives the URL of the jar file (relative to the codebase).

And now it gets confusing. Version, as an attribute of the jar element, is defined as "The requested version of the jar file". This is clearly not what is meant by the j2se version attribute in mine and the notepad jnlp file. And typically for this "non" tutorial, j2se, one of the tags used in their own example, does not appear in the elements table. What does appear as an attribute of the jar element is main, which: "Indicates if this jar contains the class containing the main method of the application", but again typically for this non-tutorial, no syntax or range of values is given.

The final element used in the example file is application-desc, which "Indicates if this jar contains the class containing the main method of the application", and the only attribute of this element is main-class, "The name of the class containing the public static void main(String[]) method of the application".

Maybe, therefore, the syntax of the attribute main in the element jar is similar to main-class in application-desc. Certainly that would be logical. Unfortunately the designers of java seem to have a rather limited grasp of logic, so I am not holding my breath, but I will try it. I'll remove the element j2se and it's attribute href (because according to the table it is not needed), and replace it with the attribute main. The finished file will look like this:

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for ActiveMath -->

<jnlp spec="1.0+"
codebase="http://202.65.70.207/myweb/"
href="AMJ002.jnlp">
<information>
<title>Active Math Java Test</title>
<vendor>Softway Interactive Education</vendor>
<description>Active Math Java Test</description>
<homepage href="http://202.65.70.207/myweb/index.htm"/>
<description kind="short">ClickMeApp uses 1 custom class plus 1
standard one</description>
<offline-allowed/>>
</information>
<resources>
<jar href="ActiveMathJA002.jar/ main="AMJFormA002"/>
</resources>
<application-desc main-class="AMJFormA002"/>
</jnlp>

I still can't get the sodding thing to work, but I have doubts about that main attribute, and the forward slashes, which seem to be scattered through the notepad.jnlp file quite at random.

Comments

Popular posts from this blog

A few notes on JavaScript

Forum Comments on Java Applets

Creating a Custom Swing Component