jws application can't load swing-layout - java

I have an old application that use swing-layout and i have to make it usable via java webstart . It runs fine from netbeans but if I launch it using jws I got this error :
exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at Gui.Accueil.jMenuItemConsPHActionPerformed(Accueil.java:2331)
.....
Caused by: java.lang.ClassNotFoundException: org.jdesktop.layout.GroupLayout$Group
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 41 more
I have tried to add swing-layout in the jnlp file but I get this error when I run it :
com.sun.deploy.net.FailedDownloadException: Impossible de charger la ressource : http://my_url:8080/___JWSappclient/___app/test/lib/swing-layout-1.0.4.jar
this the jnlp :
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>test </title>
</information>
<eligible>True</eligible>
<security>
<all-permissions/>
</security>
<resources>
<jar href="./lib/swing-layout-1.0.4.jar"/>
</resources>
</jnlp>
Thanks .
First edit :
I have removed and tried with many path but it's almost the same error com.sun.deploy.net.FailedDownloadException: Impossible de charger la ressource : http://url/___JWSappclient/___app/test/lib/swing-layout-1.0.4.jar
I tried to change swing-layout name to sl.jar but it didn't help .
What I dont understand is why jws try to download the swing-layout.jar from the server ?

The element <eligible> does not appear in the JNLP File Syntax, and your file is malformed as shown. In your previous question on this topic, you mentioned needing to support Java 6. To support Java 5, specify it in <resources>. The JAR containing org.jdesktop.layout.GroupLayout appears correct, but the path is suspicious. Try something like this:
<resources>
<j2se version="1.5+" />
<jar href="lib/swing-layout-1.0.4.jar"/>
</resources>
Addendum: I don't understand why JWS tries to download the swing-layout.jar from the server.
The JNLP client downloads all JARs from the server via HTTP. Each JAR must be accessible using the relative path specified in the href attribute. In particular, the directory containing your application JAR and JNLP file must also have a lib directory containing the layout JAR.
test/
application.jnlp
application.jar
lib/
swing-layout-1.0.4.jar

Related

File Not Found when using Java Web Start

I'm trying to use Java Web Start to replace a Java applet, but every time I run the .jnlp file either directly from the web server or directly from my computer it gives me an error.
I see the Java Web Start splash screen, and then the default progress bar appears. It downloads, and then verifies my jar, but shortly afterwards the following error message appears "Unable to launch the application".
CouldNotLoadArgumentException[ Could not load file/URL specified: C:\Users\[username]\AppData\Local\Temp\tmp_cache9015150161909242571.tmp]
at com.sun.javaws.Main.launchApp(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(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Users\[username]\AppData\Local\Temp\tmp_cache9015150161909242571.tmp (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
at com.sun.javaws.Main.launchApp(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(Unknown Source)
I see no files in the Temp folder that look anything like tmp_cache.
Here is my JNLP file:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://localhost:2020/MyServer/applets"
href="basicTest.jnlp">
<information>
<title>JWS Test</title>
<vendor>My Company</vendor>
</information>
<resources>
<j2se version="1.7+"
href="http://java.sun.com/products/autodl/j2se"/>
<jar href="basicTest.jar" main="true" />
</resources>
<application-desc
name="Test Name"
main-class="main.Entry">
</application-desc>
<update check="background"/>
</jnlp>
Things I've tried:
Downloading the JNLP file and the JAR from my web server (Works as expected)
Using a brand new, bare-bones jar with nothing but a main method and a System.out.print() statement (Same result)
Changing the href inside the .jnlp file (Different error message, can't find .jar, as expected. My server logs show this correctly as a 404)
Changing the value of the main-class attribute (Same result, suggests that the JVM never starts)
Running other example apps from Sun (These work correctly, either when running through the browser or when running downloaded .jnlp files)
Clearing my java cache and temp files (Same results)
I did wonder if the jars not being fully signed would matter (my jar is currently self-signed while in development) but I would expect a different error in that case.
It seems as though the jar file is downloaded into one location, and verified, but then can't be found when the JVM tries to start it. Could there be a cache location conflict?
One of the reason can be JRE 7 onwards security is high .Signing jar is required.

FileNotFoundException during JNLP download

I was looking for a solution of this problem for weeks now, but did not find anything, which really related to my problem / or I already tried all suggested solutions, without any success.
I have a JNLP file, which is downloaded by the javaws properly (I think), but then before launching, it complains about not finding some files in the /tmp directory. Exact error message is:
CouldNotLoadArgumentException[ Could not load file/URL specified: /tmp/tmp_cache8259898691262575141.tmp]
at com.sun.javaws.Main.launchApp(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)
Caused by: java.io.FileNotFoundException: /tmp/tmp_cache8259898691262575141.tmp (Nincs ilyen fájl vagy könyvtár)
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.FileInputStream.<init>(FileInputStream.java:93)
at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
... 5 more
I checked the /tmp, the folder is of course there, and is writable. Funny thing is, that during downloading the tmp_cacheNNNNNN.tmp files are there! They appear one-by-one, as the download progress moves on. However when the download is finished something (javaws?) deletes all of them, and then starts to complain about missing them.
I have JNLP caching turned on (and intend to have it cached locally). I tried with JRE 1.8.0_40, 1.8.0_65, 1.8.0_66, all gives the same result. Same result on windows and linux, both complain about missing files in the temp folder.
The last JRE I managed to start is the 1.8.0_25, and seems to work with 1.8.0_72 (beta). However the downloaded jar files are still not cached! (if I open up the jcontrol application and look into the cache, the JAR files are not there, and I also don't know why).
My JNLP looks like this:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="7.0+"
codebase="http://localhost:8080/jbaf-server/jnlp/swing-client"
href="http://localhost:8080/jbaf-server/clientDownload/client.jnlp" >
<information>
<title>Swing Client</title>
<vendor>www.xy.z</vendor>
<description>Swing Client</description>
<description kind="short">Swing Client</description>
<homepage href="www.xy.z"></homepage>
<icon href="images/jnlp-icon.png"/>
<icon kind="splash" href="images/jnlp-splash.png"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.8+" initial-heap-size="256m" max-heap-size="1024m"/>
<property name="jnlp.versionEnabled" value="true" />
<jar href="jbaf-swing-client.jar" version="0.3.0" main="true"/>
.... (lots of jar files)
<jar href="spring-expression.jar" version="4.2.3.RELEASE"/>
<jar href="spring-tx.jar" version="4.2.3.RELEASE"/>
<jar href="commons-codec.jar" version="1.10"/>
</resources>
<application-desc main-class="org.jbaf.swingclient.Main">
<argument>http://localhost:8080/jbaf-server</argument>
<argument>false</argument>
</application-desc>
</jnlp>
The JARs are signed with self-signed cert.
I have no idea why this happens. Anyone faced such a problem?
Finally I managed to find the problem!
It was caused by following HTTP headers set by Tomcat:
Cache-Control
Pragma
Expires
I did not set these headers in my Servlets, but it seems that these were added by some of the filter previously. I set these header values to "" (empty string), and the JDK started to cache my files, and the application was started finally OK!
However if you set the Cache-Control to no-cache, the JDK still fails to start the application. The files are saved to the System/User temp directory, but afterwards it will not start, because the temp files are removed. This was only working with JDK 1.8.0_72 (BETA), all previous version failed!
Long story short: if you have problems with your JNLP where the WebStart tells you not finding files in the temp directory, check your HTTP Response Headers!

Java Web Start NumberFormatException while running Jar application

While trying to run Jar application using JWS (JNLP) launch. It has been giving me this error. Can't even find where is the mistake. Any directions would help.
If someone could tell me where is the potential location of this error, I could find post that code here.
java.lang.NumberFormatException: For input string: "\Tools_Dev\TestApp\dist"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.sun.deploy.security.DeployManifestChecker.verifyCodebaseEx(Unknown Source)
at com.sun.deploy.security.DeployManifestChecker.verifyCodebase(Unknown Source)
at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
at com.sun.javaws.security.AppPolicy.grantUnrestrictedAccess(Unknown Source)
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.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Note: I have the latest Java 8 installed and working on Netbeans.
The jar file works well if called manually, java -jar testTool.jar
Update:
JNLP File Content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="file:/C:/Tools_Dev/TestApp/dist/" href="launch.jnlp" spec="1.0+">
<information>
<title>Java Tool Update Test</title>
<vendor>Local</vendor>
<description>Test Tool</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<update check="background"/>
<resources>
<j2se version="1.7+"/>
<jar href="Java-Tool-Update-Test.jar" main="true"/>
<jar href="lib/sqlite-jdbc-3.7.15-M1.jar"/>
<jar href="lib/poi-3.10-FINAL-20140208.jar"/>
<jar href="lib/poi-ooxml-3.10-FINAL-20140208.jar"/>
<jar href="lib/poi-ooxml-schemas-3.10-FINAL-20140208.jar"/>
<jar href="lib/dom4j-1.6.1.jar"/>
<jar href="lib/xmlbeans-2.3.0.jar"/>
<jar href="lib/jaxen-1.1.6.jar"/>
</resources>
<application-desc main-class="Tool.Test.Main">
</application-desc>
</jnlp>
Errors prompted in JaNeLa tool excluding warnings and optimizations:
JaNeLA Report - version 11.05.17
cvc-complex-type.2.4.a: Invalid content was found starting with element 'security'. One of '{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'security'. One of '{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.
Lazy downloads might not work as expected for lib/sqlite-jdbc-3.7.15-M1.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/poi-3.10-FINAL-20140208.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/poi-ooxml-3.10-FINAL-20140208.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/poi-ooxml-schemas-3.10-FINAL-20140208.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/dom4j-1.6.1.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/xmlbeans-2.3.0.jar unless the download 'part' is specified.
Lazy downloads might not work as expected for lib/jaxen-1.1.6.jar unless the download 'part' is specified.
Posting this here in case someone has that very same error, even with java 8 Update 101:
In our specific case, after a few hours of digging, the problem ended up being that NetBeans version 7.4 was putting some useless junk on the Codebase property of the jar's MANIFEST.MF; by going into the project properties, Application -> Web Start and then changing Codebase to User defined and Codebase Preview to *, the application started working correctly.
Please do keep in mind that we're using an applet instead of a JNLP application, so your mileage may vary.
Looks like a known issue... See Bug #236765
Upgrading your Java version as specified in the bug.
Not a NB issue, javaws problem. I've tested
https://netbeans.org/kb/73/java/javase-jws.html with JDK 1.7.0_45 and
works fine.Please update JDK JRE.

Set jna library path for an applet

I am trying to run a unsigned applet jar locally.
It uses several jar dependencies and some of those need native dlls. But I do not know how to point those dlls from the applet when deploying it on a browser.
When running using eclipse applet viewer I have set,
System.setProperty("jna.library.path", "<path>");
And it worked fine.
But when I deploy same on IE 10 it gives me the below exception
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jna.library.path" "write")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at com.neurotec.samples.SimpleFacesApplication.<init>(SimpleFacesApplication.java:88)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
I want to know where to put those dlls when loading from a browser.
Thanks in advance.
UPDATE
I have tried adding all the dlls to a new jar file called nativelibs.jar and added the entry <nativelib href="nativelibs.jar"/> to my applet JNLP file. But the issue is still remains same giving
java.lang.UnsatisfiedLinkError: Unable to load library 'NCore': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:194)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:283)
at com.neurotec.lang.NCore.<clinit>(NCore.java:104)
Now the resources tag of my JNLP file is like
<resources>
<!-- Application Resources -->
<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" />
<jar href="myApplet.jar" main="true" />
<nativelib href="nativelibs.jar"/>
</resources>
Any body have an idea, what is my mistake?

JNLP: Loading unsigned code within signed code

We're having difficulties getting past the mixed code error for Java webstart. In summary, we have our main JNLP file, we've signed all of our code that it loads directly. We've added the all-permissions option to the main JNLP. The main class it loads also comes from a signed jar.
When the main class kicks off a little down the road it fires off some things that need to load some unsigned resources that are pulled in from JNLP B. None of JNLP B's resources are signed and they do not need any special permissions.
All of the signed code has been setup based on the mixed code documentation from Oracle and the jar files have been set with manifests of "Trusted-Library: true" before signing.
When the unsigned code is attempted to be loaded by the signed code we get a class not found error like so:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/some/external/package/that/is/not/signed
at org.our.signed.package.main(Main.java:87)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.some.external.package.that.is.not.signed
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
Here's the scenario in the JNLP's:
JNLP A: (summarized)
<jnlp spec="1.5+" codebase="...." href="......">
<information>
...etc
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" initial-heap-size="80m" max-heap-size="256m" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="signedJar_1.jar" download="eager" main="true"/>
<jar href="signedJar_2.jar" download="eager" main="false"/>
<extension name="unsigned_ext" href="unsigned.jnlp"/>
</resources>
<application-desc main-class="(FROM SIGNED CLASS in signedJar_1.jar)"/>
</jnlp>
JNLP B (the unsigned.jnlp loader)
<jnlp spec="1.5+" codebase="....." href="......">
<information>
...etc
</information>
<resources>
<jar href="unsigned.jar"/>
</resources>
<component-desc/>
</jnlp>
We have noted that the security exceptions are working correctly, because if we move the unsigned jar into the the JNLP that has all-permissions and has signed jars, we get the expected security exceptions that Java won't let us mix the signed code with Trusted-Library: true and unsigned code with no manifest attributes.
Ideas? Is there a reason the classloader can't find the java files from the unsigned code? Is there something special we are missing to allow signed code to run unsigned code? I've only seen the cases where people have problems getting unsigned code to run signed code, which I can understand.
The trusted-library class loader is a parent (in the sense of class loader delegation) of the (possibly untrusted) applet class loader. Think of it as if it is the boot class loader. So the untrusted classes can link to the trusted-library classes but not vice versa. Without going to the bother of altering manifests and using WebStart you can try this stuff out by adding your trusted class with -Xbootclasspath/a: and your untrusted classes with -classpath (this is how the feature was tried out before it was implemented).
JNLPAppletLauncher is an example of how to have trusted-libraries invoke applet code. The applet class loader can be obtained with Thread.currentThread().getContextClassLoader(), and it's just reflection from there. Writing safe trusted library code is tricky. Remember, you can't trust untrusted code.

Categories

Resources