I'm running an application from a jnlp file that contains useful information such as the vendor, a description, and other field.
What is the most reasonable way to get this data at Runtime in order to build an "About" dialog ?
Is there a way to detect that the application has been launched without Java Web Start ?
Thanks for your help.
Pierre
Right-click a JNLP file and click “Open With.” Select the “Java Web Start Launcher” application in the list or click “Browse,” browse to the “C:\Program Files (x86)\Java\jre[version]\bin” folder on your computer and double-click the “Javaws.exe” program file.
Oracle has announced that Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start (containing the javaws tool) are all deprecated in JDK 9 and will be removed in a future release.
The javaws command launches Java Web Start, which is the reference implementation of the Java Network Launching Protocol (JNLP). Java Web Start launches Java applications/applets hosted on a network. If a JNLP file is specified, javaws will launch the Java application/applet specified in the JNLP file.
There are various strategies to achieving the desired goal. I will not revisit those already mentioned, but instead outline several more.
1) Information can be placed in the manifest of an archive. It can be retrieved using methods of the java.lang.Package class.
String title = pckg.getImplementationTitle();
String vendor = pckg.getImplementationVendor();
String version = pckg.getImplementationVersion();
The Package class also has the ability to identify all loaded packages.
Package[] package = Package.getPackages();
Iterate that looking for your packages and you can gain a list of all the packages currently loaded.
The best way to put the information into the manifests is using Ant or some similar build tool. That way the version can be set to the date - easy done.
2) Add a property to the resources section of the JNLP.
<resources>
..
<property name="jnlp.href" value="${href}" />
..
</resources>
BTW - that use of ${href}
is intended to mean the exact same string used as the JNLP href attribute.
Use the BasicService.getCodeBase() method to obtain the codebase. Form an URL to the JNLP file using ..
URL urlToJnlp = new URL(
basicService.getCodeBase(),
System.getProperty("jnlp.href") );
Load the JNLP file and parse it using one of the plethora of XML APIs of the J2SE. (And if it does not load in the XML APIs of the J2SE, it strongly indicates it is invalid or malformed - and should be checked using a tool such as JaNeLA.)
Once it is loaded and parsed, the basic information can be obtained & presented.
You can detect if the application was launched using webstart by checking on the availability of the jnlp services. Something like:
public boolean launchedByJNLP(){
try {
ServiceManager.lookup("javax.jnlp.BasicService");
} catch (UnavailableServiceException e) {
return false;
}
return true;
}
As for getting jnlp information for an About dialog, I think your best solution is to include whatever information you want in your about dialog in a separate properties file packaged with your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With