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.
Related
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.
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.
I am working in a such environment, where we have to update client jar in every 2 months maximum. So, as a solution I am suggesting to use JNLP by using this approach we do not have to worry that every user is using the latest release or not. As, There are more then 100 clients per department.
But the problem is JNLP isn't upgrade the new jar file in the following is the my.jnlp file
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://192.168.1.26:8080/" href="Test.jnlp">
<information>
<title>HC</title>
<vendor>DRL</vendor>
<homepage href="http://192.168.1.26:8080/" />
<description>DRL</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="JnlpTest.jar" download="eager" />
</resources>
<application-desc
name="HC-DRL"
main-class="com.drl.simap.client.module.ui.Splash" />
</jnlp>
My working environment:
Tomcat-6.0 server and following tutorial
here
If you download the jnlp spec and look at chapter 6, there is a whole section about caching: "6 Downloading and Caching of Resources"
You can try to add a version number to your jar file and then use the jnlp jar version attribute.
If you currently don't do that, the spec states the following:
An entry downloaded using the basic download protocol must be located
in the cache based on the URL. The time stamp obtained from the HTTP
GET request in the Last-Modified header field of the reply should be
stored along with the downloaded resource. The time stamp is used to
determine if the copy on the server is newer.
The JNLP Client cannot assume that the HTTP GET request will return
the same JAR file for each request. The JNLP Client must periodically
check the Web server to see if an updated version is available. This
check is recommended to be performed before an application is
launched, but the exact algorithm used by a JNLP Client depends on the
particular implementation. For example, if a JNLP Client is offline,
the check is not required to be performed.
The above caching rules also apply to extension descriptors downloaded
using the extension download protocol where the version attribute is
not specified.
I'm trying to run my JNLP within an HTML page, but the java plugin does not run the JNLP, runs only the Applet.
Here is my code:
<applet width="800" height="500" codebase="http://127.0.0.1:8888/applets/"
code="br.com.app.server.utils.CompatibilityApplet"
archive="CompatibilityApplet.jar">
<param name="jnlp_ref" value="http://127.0.0.1:8888/applets/testehellojws.jnlp">
</applet>
Thanks.
[EDIT]
An example:
http://java.sun.com/javase/ja/6/ea/6u10/plugin2/jnlp/CompatibilityApplet.java
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="6.0+" codebase="http://127.0.0.1:8888/applets/" href="testehellojws.jnlp">
<information>
<title>App Hello</title>
<vendor>My App Jnlp.</vendor>
<homepage href="http://127.0.0.1:8888/Home.html"/>
<description>My App Jnlp</description>
<description kind="short">Appr</description>
<icon href="images/icone.jpg"/>
</information>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="hello.jar" main="true"/>
</resources>
<application-desc main-class="br.com.app.server.HelloJWS"></application-desc>
</jnlp>
Please edit your question and just let me know it is edited.
OK
Did you miss the part about the documentBase?
I didn't.
I would recommend removing the space in the applet name attribute.
Done
Can you run any other JNLP embedded applets? E.G. the small (sand-boxed) GIFanim applet at my site?
Yes
What info. do you get reported from here?
java.vendor: Sun Microsystems Inc.
java.version: 1.6.0_26
os.name: Windows 7
os.version: 6.1
<application-desc main-class="br.com.app.server.HelloJWS"></application-desc>
That is the descriptor for a Java application (as opposed to an applet). For an applet, use something more like..
<applet-desc main-class="br.com.app.server.HelloJWS"></applet-desc>
Note:
Even that is not a correct descriptor for an applet, which must explicitly state a documentBase, name, width & height. See the applet-desc section of the JNLP File Syntax for more details.
It must (of course) be an applet. It is not possible to 'embed' an application into a web page using this technique.
JNLP and the Java Plug-In (required for both applets and web start) was deprecated and removed from the API in Java 9.
Your jnlp_ref should probably be an absolute URI, e.g. http://127.0.0.1:8888/applets/testehellojws.jnlp
Also there is a stray space at the start of your code value (though this is probably not the cause of your problem.)
Checking on a related post, I decided to test the tag
<OBJECT>
.
I thought that this would not work with JNLP, so we had tested before.
After changing
<APPLET>
to
<OBJECT>
and referencing my jnlp file as a parameter, it worked!
The browser ignores the code and archive parameters and run my JNLP.
thanks.
Try to remove [archive="CompatibilityApplet.jar"]
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).