And another thing...
Tim Quinn's Blog

Thursday Feb 09, 2006

Some app clients may accept command-line arguments or use certain property settings. This post describes how you use the GlassFish Java Web Start feature to pass them to your app client.

You are probably used to just putting these settings on the appclient command line like this:

appclient -client myclient.jar -Dcolor=red -shape rectangle

It's not quite that simple when you launch the client using the Java Web Start feature in GlassFish. But it's not too bad.

Passing Arguments

You can specify arguments and properties by adding a query expression to the URL you use to launch your app client. Any query parameter with the name arg is passed exactly as-is as a command-line argument to the app client. If your client expects arguments like this:

-shape rectangle

then you will pass two arguments like this:

http://<host>:<port>/<launch-url>?arg=-shape&arg=rectangle

(See my earlier posts about the default URL path and how you can customize the path.) Note that the minus sign that introduces the “shape” keyword is included in the first query parameter value. It's your client – not any GlassFish code – that interprets the minus sign as a keyword introducer, just as with any Java application you might write that deals with command-line arguments. That's why you set “-shape” and “rectangle” up as two separate arguments in the query string.

Setting Properties

Suppose your client works with a property that you might normally specify on a Java command line using

-Dcolor=red

for example. You can specify properties via the Java Web Start feature using prop query parameters in the URL:

http://<host>:<port>/<launch-url>?prop=color=red

Notice that the GlassFish Java Web Start feature will interpret everything after the first equals sign in the “prop” expression as <property-name>=<value>. So in this example the property “color” will be set to the value “red.” The setting ?prop=equation=y=2*x would set the property “equation” to the value “y=2*x” when your client is started. The setting ?prop=xyz would set the property “xyz” to the empty string.

Arguments and Properties

You can combine arguments and properties in any order. Your client will receive the arguments in the order they appear in the query string. Here is an example that assigns the arguments and properties from the earlier examples in one URL:

http://<host>:<port>/<launch-url>?arg=-shape&arg=rectangle&prop=color=red

You probably do not want end-users to have to type such URLs into their browsers to launch the app client. Consider building a web page with a link that includes the query string. Or perhaps a dynamic page would gather some input and prepare the URL for the user accordingly.

Comments:

Shouldn't all the scripts in GlassFish follow one guideline. asadmin seems to follow the standard POSIX kind of style whereas other command lines including appclient don't. Shouldn't it be uniform?

Posted by Kedar Mhaswade on February 14, 2006 at 10:10 AM CST #

Is there any way of passing in JVM options via the URL? Such as -Xms2048?

Can any element of the JNLP file be provided in the URL, such as providing a resource (e.g. pointing to a library already on the client system)? I guess this could be achieved via the 'prop' option, in that java.class.path could be set, but is it possible to append libraries to the classpath like you would do in the <resource> tags of the JNLP rather than have to specify the entire classpath?

Posted by Anonymous on August 09, 2007 at 10:07 AM CDT #

There is currently no way to provide arbitrary JNLP content to be used in launching the client. There are a very few customizations available (specifying the vendor text and icon images) today described elsewhere in this blog.

One of the features we would very much like to add is the ability for the developer to influence or customize the generated JNLP much more extensively. Rather than doing so in the URL, I expect we would allow the developer to package a JNLP file with the app client that would be used to govern the generation of the JNLP document.

Pointing to resources on the client system sounds tricky because different client systems might have the same resource in different places. One possibility you might consider: JNLP provides an API, accessible to the client program, that asks the user to specify a file to be opened, etc. (The prompting is an outgrowth of the Java Web Start security model.) See the JNLP specification for more information on the API. Depending on exactly what you want to accomplish it might meet your needs.

Posted by Tim Quinn on August 14, 2007 at 02:50 PM CDT #

Post a Comment:
  • HTML Syntax: NOT allowed