Referencing jars in jnlp file - java

I have the below JNLP file. I have created the appropriate folders, when the jnlp file downloads, message the system cannot find the specified path is seen at the console.
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.5" codebase="http://localhost:8080/myapp/jars">
<information>
<title>MyApp</title>
<vendor>MyApp</vendor>
</information>
<resources>
<jar href="main.jar"/>
<jar href="jcalendar.jar"/>
<jar href="apps/jdi.jar"/>
<jar href="JGo.jar"/>
</resources>
<security>
<all-permissions/>
</security>
<application-desc main-class="com.myapp.jars.Main">
</application-desc>
</jnlp>
Java Web Start 1.6.0_22
Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\
<----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
0-5: set trace level to
/myapps/jars/main.jar
/myapps/jars/jcalendar.jar
\myapps\jars\apps\jdi.jar(The system cannot find the path specified)
/myapps/jars/jGo.jar
I have the jars signed, and placed them under the folder jars/apps/jdo.jar
Could some one help me.
Thanks,
Karthik
When I include along with other jars within jars folder, the console throws Unable to load the resource file (jdi.jar)
com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://localhost:8080/myapp/jars/jdi.jar
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Is the missing jar really in a folder called apps at http://localhost:8080/myapp/jars/apps/jdi.jar ? If jdi.jar is in same place as other jars, try:
<jar href="jdi.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.

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?

jws application can't load swing-layout

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

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