Passing arguments on a jnlp file - java

Is it possible to pass maven-like arguments on a JNLP file?
<jnlp spec="1.0+" codebase="${javafxCodebase}" href="Foo.jnlp">
<information>
<title>${javafxTitle}</title>
<vendor>${javafxVendor}</vendor>
...
</information>
...
</jnlp>
And if so, who will pass these data to the jnlp file? What comes to mind is:
http://localhost:8080/Foo.jnlp?javafxCodebase=bar&javafxTitle=baz

There is no support for this out of the box with Java Webstart. There is a JNLP Download Servlet but it only supports a limited set of macros and cannot have any that are user defined.
I think your best approach would be to use a templating engine like Velocity to write your own servlet for generating the JNLP file on the fly and populating it with your required arguments.

You can also try the php script on this website.
I found it useful to automatically detect my codebase url, since I had a requirement to deploy the jnlp files on different servers.

Related

Use GAE servlet to serve dynamic JNLP and jar for JavaWS

I encourtered several problems when I try to distribute jar/jnlp dynamically. All my files are dynamically served using http://www.mywebsite.com/ServeFile?name=xxx for file xxx. I can download files correctly.
When I put the link to jnlp in the browser and download, there is an error from javaws showing that the jar file was not found. The GAE log file shows that the javaws tried to load /ServeFile.pack.gz?name=test__V1.0.jar so it wasn't served by the ServeFile servlet, instead it was served by / (which is another servlet)
Here is my jnlp file partial content:
<resources>
<j2se version="1.6+"/>
<jar href="ServeFile?name=test.jar" main="true" version="1.0"/>
<property name="jnlp.packEnabled" value="true"/>
<property name="jnlp.versionEnabled" value="true"/>
</resources>
My question is how does the javaws put .pack.gz into the middle of the url, instead of just putting a AcceptEncoding in the request? What is the right way to serve jnlp and jar dynamically?
Update
Problem solved when using a "static" type link such as http://website.com/path/file.jar without using ?file=file.jar. I still have a problem:
New Problem
JavaWS will sometimes put ?version-id=1.0 and my dynamic url is also using similar pattern like ?folder=root&user= guest. So version-id would become 1.0?folder=root.
If I put &folder=root&user=guest it would work, but javaws sometimes request myjar__V1.0.jar& folder=root so now the file name has myjar_ V1.0& folder=root which is wrong. It's not consistent.
Temporarily, I can just parse this version-id to see whether it contains a question mark. I hope there is a better solution.
On GAE, consider putting the files in the blobstore and using the blobstore service to serve them up.
The Blobstore can serve any binary file
https://developers.google.com/appengine/docs/java/blobstore/overview
I got a temporary solution but yet another problem. This jar is stored in datastore, so I need http://www.myserver.com/?file=start.jar to access it. Once I use http://www.myserver.com/start.jar it then works. I just need my servlet to parse the Path instead of getParameter which is still easy.
Problem is with pack.gz and version-id. If you link is http://www.myserver.com/start.jar?folder=root&user=guest then javaws would generate http://www.myserver.com/start.jar.pack.gz?version-id=1.0?folder=root&user=guest for which your getParameter("version-id") is 1.0?folder=root so you possibly think you could use &folder=root&user=guest
But your link could also become http://www.myserver.com/start__V1.0.jar.pack.gz?folder=root&user=guest (which is good). I don't think you can guarantee which one javaws uses so you can't prepare to use ?folder=root or use &folder=root.

JNLP file: not to create desktop shortcut

In our webstart JNLP file, I have removed the shortcut and desktop tag, but when installing the webstart app, it still prompts me if I want to create a desktop shortcut.
So in the information tag it looks like this:
<information>
<title>Dynamic Tree Demo</title>
<vendor>Dynamic Team</vendor>
<icon href="sometree-icon.jpg"/>
</information>
Is there any way to do this?
Your best bet is to add query params to the href e.g. if the current value is the.jnlp, make it the.jnlp?a=b. The JWS client will presume it is generated dynamically and will generally not create a desktop shortcut.
I say 'generally' since it is really up to the JWS client & how it is configured.

Deploy JNLP applet *without* Next Gen Java Plugin

I need to deploy an applet on a .jsp page and want to take advantage of lazy loading and pack200 that you get when using JNLP. However my client does not have the Next Gen Java Plugin enabled on their machines and they do not want to enable it. This means I can not take advantage of the jnlp_href attribute introduced in java 1.6.10.
After some research I discovered you can specify an applet-desc in my jnlp but I am new to JNLP and do not know how to fully take advantage of this tag.
I have not seen any solid examples of how to use a JNLP file on a webpage without using the applet or object tags which require the jnlp_href param attribute.
Is it possible using this applet-desc tag to inject a reference to my JNLP in my .jsp page?
Currently I specify my applet using the object HTML element like this:
<object code="<myappletClass>" name="pdfapplet" codebase="<myCodeBase>" mayscript>
<param name="jnlp_href" value="my-applet.jnlp"/>
</object>
However this does not grab the jnlp_href with Java plugin turned off in the Java console.
If the applet does not need to be embedded in the web page, it can be launched free-floating from the first versions of Java Web Start (available as a separate download around Java 1.2). It is only in the Next Generation JRE that a JWS deployed applet can remain embedded in a web page.

Dynamic JNLP Generation and invocation from Excel

I have an application which is invoked via Java Webstart. Opening it via the Webstart link works without any issue.
I also have an application based on Excel that generates files (via vba) which can then be opened by the program that starts via Webstart.
What I would like to do is have a button that invokes the Webstart application and then opens a newly generated file. The files name (and contents) are time sensitive and so I can't use the same file name over and over.
I've pretty much figured out how to use vba to invoke the application via Webstart but the problem is that for the Webstart app to be able to open a file it needs to be passed in as an argument in the jnlp descriptor
<application-desc main-class="com.foo.WebstartApp">
<argument>-file</argument>
<argument>C:\files\file_20100909_164834.csv</argument>
</application-desc>
How do you go about passing through the filename into the JNLP file when the filename will always be different?
Should I be looking at dynamically generating a new jnlp file each time, or is there a way to parameterize the jnlp file and pass through the filename when invoking the JNLP?
Dynamically generated JNLP files is probably going to open you up to injection attacks, just like dynamic SQL. Further it looks as if you are expecting the user to trust the WebStart application which trusts the JNLP file which is untrustworthy.
Assuming you have one application instance per desktop (SingleInstanceService), information about which files to use, which should not necessarily be trusted, can be passed through an applet using the PersistenceService ("muffins") or, apparently if the browser is IE, through cookies.
I've found a solution that suits my needs. A custom servlet is used to modify parameters in the URL string.
http://forums.sun.com/thread.jspa?threadID=714893

Can I invoking java web start in program?

I want to make use of the java web start advantage,but I dont want our customer face the java web start loading Screen,it seems ugly...and also customer maybe not install jre and the jre-install maybe fussy to them..so I want to package our application and jre into setup file using installanywhere. when user start our program,I want to invoking web start API to do the work like version compare,and offer outself loading screen ..
so,Can I invoking web start in my program?and how?
Best regards
L.J.W
I don't think web start is the way you want to go here. You can't change the loading screen, and if you want to access the user's computer in any way you'll have to bother the user with a confirmation, and risk them freaking out and canceling. Just roll your own auto-update; it's definitely not worth using web start just for that.
For the loading screen question:
<jnlp ...>
<information>
<icon kind="splash" href="splash.gif" />
...
</information>
...
</jnlp>
If you're installing your application locally on the user's machine, why would you need to call JWS?

Categories