I'm trying to figure out why my jnlp file isn't working. I'm new to all this so I'd like to check if I did everything correctly. I made a project with JavaFX, in which main class is called Main.java, and then created ExecutableJar file myApp.jar. When I double click on this jar, it opens up and everything works perfectly. Then I tried creating a jnlp file with the same name as my jar file, myApp.jnlp. I did it like this:
<jnlp spec="1.0+"
codebase="url of my site here"
href="myApp.jnlp">
<information>
<title>My Title</title>
</information>
<resources>
<j2se version="1.6+"/>
<jar href="myApp.jar" main="true" />
</resources>
<application-desc
name="Application"
main-class="Main.class"
<application-desc>
<update check="background" />
</jnlp>
In an html file I added it like this:
LAUNCH
Since I don't have any certificate for my jar file, I added url to my file into Exception Site List in Java Control Panel/Security. But when I try to run it I get an exception com.sun.deploy.net.FailedDownloadException: Unable to load resource: https://myUrlHere/myApp.jnlp
I have tried many solutions, including granting all permission in java.policy files, but nothing helped. When I tried it on another computer, on which I haven't tried any weird solutions before I got an error: "Could not find main-class Main in myUrlHere/myApp.jar" Am I doing something incorrectly? I tried running it locally, but it was even worse then. I tried to follow this tutorial: https://www.youtube.com/watch?v=BKuCfNNely4, but instead I used my school server.
Related
I've seen similar questions asked on SO before, but all of them have codebase/href values pointing to things like http://localhost:8000/test and file://D:/MyProject/Foo.jnlp instead of supporting a completely arbitrary "run out of the same local directory" behavior. People have mentioned that some combination of empty and/or missing attributes are supposed to work in recent JREs, but I can't find any combination of syntax that will work. (Normally I'd just go look through the launcher source, but can't for javaws.)
Collectively, we have a lot of experience with the Java language, but we haven't needed to use javaws before, and Oracle's documentation is... frustrating. What we've come up with, anonymized to protect the innocent:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="9+" version="x.y.z" codebase="???" href="test.jnlp">
<information>
<title>Our Stuff Name</title>
<offline-allowed/>
</information>
<resources>
<java version="9+" java-vm-args="-X:foo"/>
<java version="1.8*" java-vm-args="-X:bar"/>
<jar href="OurStuff.jar" main="true"/>
</resources>
<!-- this is apparently required for local operation even if
the JAR has a manifest with the same main() class -->
<application-desc main-class="com.example.OurStuff"/>
<security>
<all-permissions/>
</security>
</jnlp>
The JNLP file is included as JNLP-INF/APPLICATION.JNLP before signing the JAR file. (The signing and verifying go okay, and running the signed JAR by hand using a java .... -jar OurStuff.jar command line works, but of course isn't available to Windows users.)
But we don't have enough experience among us to get the codebase/href attributes right. What we've tried:
Any codebase attribute trying to refer to the current working directory, like "file://." and similar hacks, all fail with parse errors. This makes total sense. We tried that only out of desperation.
No codebase, no href in the <jnlp> element at all: "The field href has an invalid value in the signed launch file: OurStuff.jar"
No codebase, <jnlp href="test.jnlp">: "The field href has an invalid value in the signed launch file: test.jnlp"
It apparently is supposed to be able to handle only having a location URL in one place, but can't handle not having any. Grrrr.
We tried turning on tracing and cranked the trace level to high. Then it gets frustrating, because at the top of the trace file, javaws had this to say:
basic: Running JVMParams: [JVMParameters: isSecure: true, args:]
-> [JVMParameters: isSecure: true, args:]
basic: XMLParser with _source:
<?xml version="1.0" encoding="utf-8"?>
..... our entire JNLP file verbatim including comments ......
basic: Error parsing test.jnlp. Try to parse again with codebase from LAP
java.net.MalformedURLException: no protocol:
at java.base/java.net.URL.<init>(URL.java:627)
.... internals stack trace .....
Okay, fine, it needs a well-formed URL in an href. But later in the same trace, we see this:
temp: returning LaunchDesc from XMLFormat.parse():
<jnlp spec="9+" codebase="file:/C:/building/OurStuff/branchname/" version="x.y.x" href="file:/C:/building/OurStuff/branchname/test.jnlp">
<information>
<title>Our Stuff Name</title>
<vendor></vendor>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<update check="timeout" policy="always"/>
<resources>
<java version="9+"/>
<java version="1.8*"/>
<jar href="file:/C:/building/OurStuff/branchname/OurStuff.jar" download="eager" main="true"/>
</resources>
<application-desc type="Java" main-class="com.example.OurStuff"/>
</jnlp>
The codebase attribute, both of the href attributes, all of the missing/optional attributes, have all been worked out correctly! Even entire elements we left out in order to get default behavior! We were in the C:\building\OurStuff\branchname directory at the time! Yay! We thought! Except no! After a couple hundred more lines of correctly testing the signed jar's modification time, copying pieces around in its cache behind the scenes, and matching up the <java/> elements with the locally-installed JREs, it decided to ignore everything it had discovered, but instead printed out the original error and exited.
What do we need to put in the JNLP file to tell javaws "go ahead and use the results from 'codebase from LAP'", whatever LAP means? Or is there some other combination of codebase and href attributes that it will simply look in the same directory as the JNLP file, wherever that happens to be?
Having the following sample jnlp:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="$$codebase" href="$$name">
<information>
<title>Some Example</title>
<vendor>Some Sample Vendor</vendor>
<homepage href="http://www.somesamplevendorhomepage.com"/>
<description>Some Sample Description</description>
<icon kind="splash" href="link_to_some_splash.jpg"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<update check="always" policy="always"/>
<application-desc main-class="com.some.sample.Main">
<argument>--URL=SAMPLE_DB_NAME=http://localhost:<db_port>/webapplication/creds/auth</argument>
<argument>--UserTimeout=350</argument>
</application-desc>
<resources>
<j2se version="1.7+" />
<jar href="com.some.sample_1.0.0.jar"/>
.
.
.
</resources>
</jnlp>
(please ignore formatting or other inconsistencies - the only part that matters is the argument part)
Having the variable db_port within the argument tag, is there a way to pass a value to this variable when executing the jnlp with javaws?
For example: javaws /path/to/sample.jnlp 31022
EDIT:
JNLP downloads the JARs to the cache folder located (on Windows) under AppData\LocalLow\Sun\Java\Deployment\cache.
Is there a way to use the download JARs (my app has multiple JAR files) in order to have a way to execute the app providing the argument directly to the downloaded JAR?
For example:
jar -jar app.jar --URL=SAMPLE_DB_NAME=http://localhost:<db_port>/webapplication/creds/auth
PS: I understand that the files that are stored in the cache folder have a computed generated name and they are without the .jar extension.
However from the Java Control Panel GUI or from CMD/PS with "javaws -viewer" I was able to determine the file used as jnlp and launch it. I was wondering if there is a way to use some of the JARs to launch the app or maybe create a "parent" one in order to be able to pass arguments to it.
The documentation seems to be intentionally lacking on this topic, but the documentation suggests the preferred method to pass command line parameters to the javaws executable is through ‑userConfig flag.
e.g.
javaws /path/to/sample.jnlp -userConfig port 31022
The documentation doesn't provide examples for this. I even searched GitHub for javaws userConfig and only got a handful of results, so this seems to be a very rarely used feature.
Since your question specifically asks about a <port> variable contained within another variable, that is not something directly supported. You would instead need to find a way to wildcard or paramaterize the <port> using an additional variable and some search/replace inside the main class, assuming you have access to the source. If you don't have access to the source, you will be stuck writing the JNLP by hand, which can have additional work required if it's a signed file.
The end goal is to provide application client downloads using Java webstart from Glassfish 4.
I've been trying to get this working for 3 days, researching every method I can find and no matter what I try, webstart is blocked.
Exception list. Doesn't work.
Adding the certificate as a trusted certificate. Doesn't work.
Sandbox which doesn't need any permissions. Doesn't work.
Updating Java. Doesn't work.
I can't seem to find the deployment rule sets option but this sounds like something that needs full windows server integration etc.
There is no medium option in the Java console security settings as I am using java 8.0.31.
Simple test app that has nothing but static main void which prints a message to command line. Cannot get it to work...
It is starting to drive me crazy that it is impossible to develop anything using webstart, the only options I can see are purchasing a certificate for local development or totally dropping webstart...
How I added the certifacte to my machine - the certificate is shown in my Java console.
Here is the simple scenario I cannot get working:
package com.cbprogramming;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
System.out.println("Test");
}
public static void main(String[] args) {
launch(args);
}
}
I then used IntelliJ Idea to create a JavaFX application that packages it including the webstart jar file, JNLP file and html web page including custom manifest fields for permissions: sandbox and codebase.
The JNLP file, I also tried with the security and permissions tags, both all-permissions and sandbox.
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="WebstartTest.jnlp">
<information>
<title>Webstart Test</title>
<vendor>Testing</vendor>
<description>A Java Webstart testing app</description>
<offline-allowed/>
</information>
<resources>
<jfx:javafx-runtime version="8.0+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
</resources>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="WebstartTest.jar" size="1190" download="eager" />
</resources>
<security>
<all-permissions/>
</security>
<applet-desc width="600" height="400" main-class="com.javafx.main.NoJavaFXFallback" name="WebstartTest" >
<param name="requiredFXVersion" value="8.0+"/>
</applet-desc>
<jfx:javafx-desc width="600" height="400" main-class="com.test.Main" name="WebstartTest" />
<update check="background"/>
</jnlp>
And the manifest file:
Manifest-Version: 1.0
permissions: sandbox
codebase: file:///d:/test/
JavaFX-Version: 8.0
Class-Path:
Created-By: JavaFX Packager
Main-Class: com.test.Main
Name: com/test/Main.class
SHA-256-Digest: 8BK5m/ojirCK/QEx8Oe+9z/L6P8JXin0CMDK4R2mkAI=
I have added the jnlp, jar and html files to the exceptions list, I've tried both with file:// and file:///, I've also tried adding the glassfhish URL to the exception list, http and https...
I am developing on a Win 8.1 pro machine using Jdk 8.0.31.
Every forum I have read users are saying any one of these options fix their problem. What am I doing so wrong?!? Is 8.0.31 broken? Or is webstart just not worth using?
Here is what I found incase others find it useful.
It looks like Glassfish 4.1 has a webstart bug when using Java 7 update 25 or later (currently 8.0.31). The workaround is to use an older version of Java.
I never could get the java console exceptions list to work.
Adding the certificate as trusted let webstart work from a local file/html file but it still didn't work through glassfish.
The tags needed to be removed from jnlp files now that they are in the jar manifest file or the application was blocked, these tags are added automaticlly by glassfish and intellij JavaFX packager.
Another thought is to setup a local certificate authority and add it as trusted through the java console - this way it isn't a self signed certificate.
Also, to get a glassfish application client debugging in IntelliJ:
Create a batch file: start "name" cmd /c "<installdir>\glassfish\bin\appclient.bat -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -client <dir>\TEMPSClient.jar"
Create a remote debugging configuration and set it to run the created script using the external tool in the before launch section.
This uses the default ports etc. for remote debugging, and will run the application jar in the glassfish client container before attaching the debugger to it. To get console output, redirect stdout and stderr to a log file and attach the log file to your remote debug configuration.
I first tried using the embedded ACC but couldn't get that working (copy/paste from docs has functions that don't even exist...). It would be great if someone knows of a good tutorial for using the embedded ACC.
We use JNLP to deploy our Swing application to all of our users. With JNLP, you have to reference specific names/versions of any JAR dependencies, such as widget-lib-1.4.7.jar.
We have just introduced a new project that will compile as a reusable JAR, but that will be changing rapidly (every few days or so), and so the version number will change frequently. Our Swing app will depend on this new project once its completed.
Unless we change our setup, we'll have to update the JNLP and republish it every time we publish a new version of this new dependency, which, like I said, will be very frequent.
Is there any way to call Ivy from inside a JNLP, or some way of telling the JNLP to include the contents of a directory (and then have a separate process that always makes sure the latest version of the JAR is in that directory), or something we can do so that we don't have to constantly change the JNLP?
Thanks in advance!
If your JNLP is updated frequently (or needs any other per-user parameters, like upload keys), don't use a static file. Instead, create a template JNLP file with JSP, Velocity, Freemarker, or a similar template engine and fill in the JNLP's fields dynamically, such as from a database.
I'm not sure if this addresses your need, but you could use a second .jnlp for your frequently changing library. Your main application's .jnlp would refer to that .jnlp with an <extension> element.
Your main application's .jnlp would contain this:
<resources>
<j2se version="1.7+"/>
<jar href="MyApp.jar" main="true"/>
<extension name="WidgetLib" href="WidgetLib.jnlp"/>
</resources>
And WidgetLib.jnlp would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="WidgetLib.jnlp"
version="1.4.7"
codebase="http://www.company.com/myapp/">
<information>
<title>Widget Library</title>
<vendor>My Company</vendor>
<description>Latest version of Widget Library</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<jar href="widget-lib-1.4.7.jar"/>
</resources>
<component-desc/>
</jnlp>
I've got the following JNLP:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc//DTD JNLP Descriptor 6.0.10//EN" "http://java.sun.com/dtd/JNLP-6.0.10.dtd">
<jnlp spec="6.0.10" version="1.63" codebase="http://foo.example.com/msi" href="Foo.jnlp">
<information>
<title>Foo</title>
<vendor> Foo Systems, Inc.</vendor>
<homepage href="http://Foo.com"/>
<description>Foo Viewer/Editor Application</description>
<icon href="splash.gif" width="425" height="102" kind="splash"/>
<icon href="Foo.gif" width="64" height="64"/>
<offline-allowed/>
<shortcut>
<desktop/>
<menu submenu="Foo Systems, Inc."/>
</shortcut>
<association mime-type="application-x/wlog" extensions="wlog"/>
<association mime-type="application-x/mplot" extensions="mplot"/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" initial-heap-size="32m" max-heap-size="255m"/>
<jar href="jars_deployment/TimingFramework-1.0.jar"/>
<jar href="jars_deployment/iText-2.1.5.jar"/>
<jar href="jars_deployment/jai_codec.jar"/>
<jar href="Foo.jar"/>
<jar href="jars_deployment/TimingFramework-1.0.jar"/>
<jar href="jars_deployment/iText-2.1.5.jar"/>
<jar href="jars_deployment/jai_codec.jar"/>
<jar href="jars_deployment/jsch-20090402.jar"/>
<property name="apple.laf.useScreenMenuBar" value="true"/>
<property name="apple.awt.graphics.UseQuartz" value="false"/>
<property name="com.apple.mrj.application.apple.menu.about.name" value="Foo"/>
<property name="java.util.logging.config.file" value="/Users/Shared/logging.properties"/>
</resources>
<application-desc main-class="com.prosc.msi.editor.ui.test.Sandbox"/>
</jnlp>
Most everything is working. When I double-click a .wlog file, it opens up my application. However, it doesn't open the correct file. I read somewhere that JNLP was supposed to pass parameters to the main method indicating which file caused the app to be launched, but this is not happening (on OS X 10.6). I get an empty array to my application's main method.
Probably unrelated, my splash screen doesn't work :(
Any pointers on getting this working?
In a bundled application on Mac OS X, you can implement com.apple.eawt.ApplicationListener, as shown in the Mac OS X Reference Library example, OSXAdapter:
The sample also supports document handing from the Finder by implementing the handleOpenFile() method and registering for supported file types in its Info.plist file.
Addendum: com.apple.eawt.ApplicationListener is deprecated; instead consider com.apple.eawt.Application, which provides getApplication().setOpenFileHandler().
About the splash window
I think the app is just missing the right path to your images.
In this case, like you mention the codebase:
<jnlp spec="6.0.10" version="1.63" codebase="http://foo.example.com/msi" href="Foo.jnlp"> and like you said in the image:
<icon href="splash.gif" width="425" height="102" kind="splash"/>
then, your images have to be in http://foo.example.com/msi/splash.gif
You might want be sure images are in that place.... is what I'm thinking could be the cause.
About the file association.
I'm working right now in the same, and it was seeming to be working while adding a Service from the JNLP API SingleInstanceService. This service is used to register the application like a singleton instance. So, any time your application is lauched, it could retreive the parameters which were used to call you app. In this case, you can use it to see the name of the file that was double clicked on.
http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#SingleInstanceService
In page above you can find an example and a breaf explanation about that service.
The problem that I found with that, is that I could not see the file name the first time that you run the app.
I mean, this service should register the app the first time, and after this time, you will be seeing the parameters used to launch the app. So, with this service if you opened the first time your app through a double click on your associated file, you will miss the parameters, until the next double click on it. Your app now will not open another instance again, just will pass the parameters to the instantiated application.
So, I found another solution for this.
http://www.knowledgesutra.com/discuss/tpclso-implement-single-instance-application-java.om
The boy in the page above, used a jar file from inside the Java installation to see the VM instance running that was invoked to see the parameters of the launch of your app. It has the code and the jar used to do that in this same page.
Now I'm able to see the line that was calling the app, like this:
com.sun.javaws.Main -open C:\\JNLP example\\applet-cartoon\\drawingPack\\drawing_monitor\\ejemplo.ply C:\Users\IsraelAltamira\AppData\Local\Temp\javaws23
where ejemplo.ply is the file extension that I used in the jnlp descriptor.
And well, Im working in OS X 10.6.4 now, and it seems to work, but at this moment the web start is not doing me the file association, and is not doing the shortcuts to the installed app... but maybe this last solution works for both systems (at least it work from my fake hyperlink, like the line above to open the file).