How do I get my application to run with Java WebStart - java

I have been trying to figure this out on and off for a couple of weeks now and today I spent a considerable amount of time with an old professor at UTD and we still were not able to figure it out.
I have an application I've been working on that I would like to deploy as a WebStart application. I have tried doing this Self Signed and Unsigned and get different errors for both.
Right now I'm just trying to get the application to launch locally on my machine (Running latest MacOS).
I have updated my JDK to 11.0.2. Tried different configurations with signed and unsigned certificates. Tried adding the application .jar and .jnlp files to the Site Exception List in Java Console (as well as other random things to see if any error changed, which it didn't.)
Occasionally I would see that activation.jar (for JavaBeans Activation Framework from Oracle) that I have added as a dependency would come up saying that the application was being blocked because the certificate had expired. But I haven't been able to recreate this in most of the configurations I've been trying recently. I have gone through as many of the even relatively close questions posted on here and none of them have gotten me any closer to a resolution.
JNLP file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="file:/Users/Thomas/OneDrive/MSVO/dist/" href="launch.jnlp" spec="1.0+">
<information>
<title>MSVO</title>
<vendor>Thomas</vendor>
<homepage href=""/>
<description>MSVO</description>
<description kind="short">MSVO</description>
<icon href="splash_screen.jpg" kind="splash"/>
</information>
<update check="always"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="11+"/>
<jar href="MSVO.jar" main="true"/>
<jar href="lib/commons-io-2.6.jar"/>
<jar href="lib/joda-time-2.10.1.jar"/>
<jar href="lib/mail.jar"/>
<jar href="lib/mysql-connector-java-8.0.15.jar"/>
<jar href="lib/smtp-1.4.4.jar"/>
<jar href="lib/swingx-all-1.6.4.jar"/>
<jar href="lib/AbsoluteLayout.jar"/>
<extension href="jnlpcomponent1.jnlp"/>
</resources>
<application-desc main-class="Controller.MSVO_controller">
</application-desc>
For Unsigned I get the following exception:
java.lang.UnsupportedClassVersionError: Controller/MSVO_controller has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)
When I run it as Self Signed I get:
Let me know if you need any other information and I will gladly update this.
Not sure where to go from here.

Related

How to use Openjfx in a webstart application using OpenWebStart

We are migrating a Java 1.8 JavaFX/Webstart application to Java 11 using Openjfx (https://openjfx.io) and OpenWebStart (https://openwebstart.com).
We successfully migrate and run the app to JavaFx-14 (OpenJfx). To run it at the IDE now it is necessary to include the following jvm args:
--module-path 'path/javafx-sdk-11.0.2/lib' --add-modules javafx.controls,javafx.fxml
We build the App using Maven. It beautifully works on Java 1.8. It signs all jars, create the package and the jnlp file. Maven also creates an "uber jar" with all dependencies included. We migrated the POM including the new deps. We tested it by manually running the App using the uber jar file via command line (using the --module-path parameters).
We included the --module-path argument in .jnlp file:
<?xml version="1.0" encoding="utf-8"?>
<jnlp
spec="1.0+"
codebase="http://localhost:8080/download/"
href="myapp.jnlp">
<information>
<title>MyApp</title>
<vendor>Myself</vendor>
<homepage href="http://localhost:8080"/>
<description>My App</description>
<description>Migration test</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="11"
initial-heap-size="256m"
max-heap-size="2048m"
java-vm-args="-Xms256m -Xmx4096m -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=25 --module-path '/Users/chocksmith/Desktop/javafx-sdk-11.0.2/lib' --add-modules javafx.controls,javafx.fxml"/>
<jar href="myapp-5.0.0.jar"/>
</resources>
<application-desc main-class="com.mycompany.myproduct.application.App"/>
</jnlp>
Unfortunately it fails:
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:670)
We run out of ideas here. Please advise!
OpenWebStart now provides several points about running JavaFX based application in an FAQ: https://github.com/karakun/OpenWebStart/blob/master/documentation/faq/FAQ.adoc
If this does not help please open an issue at https://github.com/karakun/OpenWebStart/issues
FX must be bundled in the JDK on the client side.
We manage to make it work with Zulo Community version 13.29.11
https://www.azul.com/downloads/zulu-community/?architecture=x86-64-bit&package=jdk-fx
Use "OpenWebStart Settings.app" application to configure the right JVM on your system.

How to measure code coverage with the JaCoCo agent for a Java Web Start (JNLP) application?

Is there a way to get the JaCoCo agent attached to a javaws Web Start (JNLP) application?
I normally run the application by calling javaws app.jnlp. Here's a sample jnlp file:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://localhost:8000/" href="test.jnlp">
<information>
<title>Testing</title>
<vendor>vendor</vendor>
<homepage href="http://localhost:8080/" />
<description>Testing Testing</description>
<security>
<all-permissions/>
</security>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="test.jar" />
</resources>
<application-desc main-class="Main" />
</jnlp>
The application itself just prints "Hello world" to the console.
I tried:
set the JAVAWS_VM_ARGS="-javaagent:/path/to/jacocoagent.jar" environment varuable
set <j2se version="1.6+" java-vm-args="-javaagent:/path/to/jacocoagent.jar" /> in the jnlp
Neither of these produces a jacoco.exec file with code coverage.
Running javaws -J-javaagent:/path/to/jacocoagent.jar app.jnlp or setting JAVA_TOOL_OPTIONS="-javaagent:/path/to/jacocoagent.jar" does seem to try to load the agent but results in:
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
at java.lang.System.getProperty(System.java:717)
at java.io.UnixFileSystem.resolve(UnixFileSystem.java:133)
at java.io.File.getAbsolutePath(File.java:556)
at java.io.File.getAbsoluteFile(File.java:572)
at org.jacoco.agent.rt.internal_8db3ebe.output.FileOutput.startup(FileOutput.java:42)
at org.jacoco.agent.rt.internal_8db3ebe.Agent.startup(Agent.java:122)
at org.jacoco.agent.rt.internal_8db3ebe.Agent.getInstance(Agent.java:50)
at org.jacoco.agent.rt.internal_8db3ebe.PreMain.premain(PreMain.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "shutdownHooks")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.Runtime.addShutdownHook(Runtime.java:209)
at org.jacoco.agent.rt.internal_8db3ebe.Agent.getInstance(Agent.java:51)
at org.jacoco.agent.rt.internal_8db3ebe.PreMain.premain(PreMain.java:45)
... 6 more
Is there any way to attach the JaCoCo agent to such a JNLP JVM?
I figured it out: adding
grant {
permission java.security.AllPermission;
};
to /etc/icedtea-web/javaws.policy (path differs on Windows: C:\Program Files\Java\<java-version>\lib\security\javaws.policy) got rid of the security exceptions when running either
javaws -J-javaagent:/path/to/jacocoagent.jar app.jnlp (only seems to work on Linux)
or JAVA_TOOL_OPTIONS="-javaagent:/path/to/jacocoagent.jar" javaws app.jnlp
and the jacoco.exec file is created.
Please also note that apparently, your application needs to be signed for this to work: https://stackoverflow.com/a/16960559/1396068
As per the Java Web Start documentation, java-vm-args does not support java agents as only a limited number of VM args is supported which are deemed safe.

My java web start application only starts when verbose is set

I have a java web start application, that I try to start via
javaws.exe https://localhost:8888/myApplication/myApplication.jnlp
nothing happens (no error message; I see no process starting in the task list).
If I start it via
javaws.exe -verbose https://localhost:8888/myApplication/myApplication.jnlp
the application starts.
I can also start the application when using
javaws.exe -viewer https://localhost:8888/myApplication/myApplication.jnlp
and then starting the application from the java cache viewer.
What is the difference, that might trigger the application to run, when in verbose mode or via the viewer? Here is my jnlp file:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="https://localhost:8888/myApplication" href="myApplication.jnlp">
<information>
....
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.8.0_60+" href="http://java.sun.com/products/autodl/j2se" max-heap-size="500m" initial-heap-size="250m"/>
<!-- some jars are referenced -->
<property name="sun.java2d.d3d" value="false" />
</resources>
<resources os="Windows">
<nativelib href="mylib.jar" download="eager" />
</resources>
<application-desc main-class="myClass">
<argument>-initLogging</argument>
<argument>SETPROPERTYjavax.net.ssl.trustStore</argument>
<argument>_UNDEFINED_</argument>
<argument>SETPROPERTYjavax.net.ssl.trustStoreType</argument>
<argument>_UNDEFINED_</argument>
<argument>SETPROPERTYjavax.net.ssl.trustStorePassword</argument>
<argument>_UNDEFINED_</argument>
<argument>-locale</argument>
<argument>_UNDEFINED_</argument>
<argument>-serviceHost</argument>
<argument>_UNDEFINED_</argument>
<argument>-serviceProtocol</argument>
<argument>_UNDEFINED_</argument>
<argument>-servicePort</argument>
<argument>_UNDEFINED_</argument>
<argument>-trustStrategy</argument>
<argument>_UNDEFINED_</argument>
</application-desc>
</jnlp>
I activated the trace and log output and found an Exception occured:
java.io.FileNotFoundException: C:\ProgramData\Oracle\Java\java.settings.cfg (Das System kann den angegebenen Pfad nicht finden)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at com.sun.deploy.config.WinPlatform.readSystemConfig(Unknown Source)
at com.sun.deploy.config.WinPlatform.getSponsorOffersDisabledSettings(Unknown Source)
at com.sun.deploy.config.ClientConfig.getSponsorOffersDisabledSettings(Unknown Source)
at com.sun.deploy.panel.AdvancedProperties.saveSponsorOfferingSettings(Unknown Source)
at com.sun.deploy.panel.ControlPanel.apply(Unknown Source)
at com.sun.deploy.panel.ControlPanel.<init>(Unknown Source)
at com.sun.deploy.panel.ControlPanel.main(Unknown Source)
at com.sun.javaws.Main.launchJavaControlPanel(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Then I found this page:
https://bugs.openjdk.java.net/browse/JDK-8134475
When I activate the java browser content (Java Control Panel > Security Tab > select checkbox "Enable content for browser and Web Start application").
Then the application started...
But the problem is: I do not know why!
I had the problem, too (see my comment My java web start application only starts when verbose is set)
I solved this problem by updating Java, i.e. reinstalling Java. The file C:\ProgramData\Oracle\Java\java.settings.cfg was created again and this new java installation could open web start applications again correctly. Although older versions still had the same bug.
After an update of Java with Java 9 I need to "Enable Applets and Web Start in the browser" in the security tab of the Java control panel.

Java Web Start can't find jar with formatted version filename

I have simple-as-can-be Web Start application sitting on a file server. The directory consists of the following:
foo__V1.1.jar
runfoo.jnlp
The contents of runfoo.jnlp is as follows:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" href="http://myserver.com/runfoo.jnlp" codebase="http://myserver.com">
<information>
<title>Foo</title>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.7.0_06+" href="http://java.sun.com/products/autodl/j2se" />
<jar href="foo.jar" main="true" version="1.0+"/>
<property name="jnlp.versionEnabled" value="true"/>
</resources>
<application-desc name="Foo" main-class="com.myserver.foo.Foo" width="640" height="480" />
<update check="always" policy="always" />
</jnlp>
The issue is that Web Start is attempting to access a file at http://myserver.com/runfoo.jnlp?version-id=1.0%2B, and not finding it.
I assume there's some extra step required to have Web Start automatically grab the latest jar version in this simple instance, but after a lot of Googling all I've found is the same steps over and over:
rename file to <file_name>__V<versionnumber>.jar
Add the versionEnabled property to the jnlp
enjoy versioned goodness
The jnlp file runs absolutely fine when I specify an explicit file name, but always fails when I've tried to implement versioning.
I'm sure I'm missing something vital but I haven't been able to find it anywhere. I'm guessing that although my set-up is simple, it's not simple-as-can-be-and-also-work.
Any help will be much appreciated :)
The explicit exception is:
com.sun.deploy.net.FailedDownloadException: Unable to load resource: (http://myserver.com/foo.jar?version-id=1.0%2B, 1.0+)
I've also tried removing the + from the version specification and the same error occurs (apart from a missing plus of course). Writting foo__V1.1.jar in the jnlp file works but of course defeats the whole point of this.
The versioned file names are a convention used by the JNLP download servlet to know what to serve when the client asks for lib.jar?version=something. You need the download servlet on the server side (or you need to duplicate its behaviour in mod_rewrite rules or similar), just the plain files with versions names is not enough.
For followers, a similar issue for me
java.io.IOException: Error returned: 10 Could not locate resource
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"unable to launch application"
com.sun.deploy.net.FailedDownloadException: Unable to load resource: (http://host:port/webapp_name/app/jar-name.jar?version-id=1.5.0-20160707.182810-19, 1.5.0-20160707.182810-19)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
meant "the special internal file version.xml didn't match up right with the filenames deployed and existent in the web-app directory":
ref: http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/downloadservletguide.html

Web-start exception JNLP

So I'm a bit confused on how to sign a jar in order for it to run as a jnlp.
At present I have a jar, it runs, starts to download and verify stuff, then it gets to the end and a window pops up saying it's unable to launch, then it gives the exception:
JNLPException[category: Launch File Error : Exception: null : LaunchDesc:
<jnlp codebase="http:/SomeHost:8080/_test/" href="jnlpcomponent1.jnlp" spec="1.0+">
<information>
<title>jnlpcomponent1</title>
<vendor>SUN_MICR</vendor>
</information>
<security>
<all-permissions/>
</security>
<resources>
<jar href="lib/activation.jar" download="eager"/>
<jar href="lib/mail.jar" download="eager"/>
</resources>
<component-desc/>
</jnlp>
]
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
at com.sun.javaws.Launcher.prepareResources(Unknown Source)
at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I am fairly sure this has something to do with the jar being signed wrong / poorly... I could use some help in understanding what's going on here and how to fix it though.
Thanks a lot.
I am fairly sure this has something to do with the jar being signed
wrong / poorly
Exactly that happent, one of your jars isn't signed (properly)
What is always working for me:
unzip all jars than sign with 1 process. If is confirmed as it working, than I will remove 1-2 jar to match the original deployment design. And you will know in what jar is the problem, than easier to fix it.
You can use ANT to sign the JAR file. This way you can sign your files from within your IDE and it makes for a faster work-flow for when you deploy your appplication. Every change requires that you re-sign your application.
<project name="YourProject" default="dist" basedir="jarsigning">
<target name="signMainJar">
<signjar jar="../dist/YourApp.jar" destDir="signed" alias="WhateverYouSetIt2"
keystore="fileNameOfCerticate" storepass="passw03d" lazy="true" />
<echo message="The file was signed." />
</target>
<!-- Use this if you are using any libraries. These also need to be signed. -->
<target name="signLibs">
<signjar destDir="signed" alias="WhateverYouSetIt2"
keystore="fileNameOfCerticate" storepass="passw03d" force="true">
<path>
<fileset dir="lib" includes="*.jar" />
</path>
</signjar>
<echo message="The library files were signed." />
</target>
</project>
Before you can run this script, you need to first create a jarsigning directory and place a certificate (key) to be used for signing. Inside that folder, create a folder called "signed" and this is where your signed code will be placed by the script. Use the keystore tool to create a self-signed certificate if you have not purchased one from a granting authority like Verisign or GoDaddy.

Categories