Java Applet Development - pack200 .gz file unpack and create .jar file in browser.
I have to test the speed after loading the .gz file in browser and I am having java applet based web application(Hello word) whose HelloWorld.jar file size is 743byets and using pack200 tool compressed to .gz(321 bytes)files.
1) created HelloWorld.java file
Code :
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello word!", 50, 25);
}
}
Created HelloWorld123.jar file with this class
2)Main html file hello.html
HTML Code:
<HTML>
<head>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">
<meta HTTP-EQUIV="accept-encoding" CONTENT="gzip,deflate">
<meta http-equiv="content-type" content="text/html">
</head>
<BODY>
Here is the output of my program:
<APPLET CODE = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar" WIDTH = "200" HEIGHT = "50">
<param name="java_arguments" value="-Djnlp.packEnabled=true"/>
</APPLET>
</BODY>
</HTML>
3)First time tried to load the class file from the jar file it works fine(HelloWorld.class is loading in the browser).
HTML Code:
<APPLET CODE = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar" WIDTH = "200" HEIGHT = "50">
4) created different .gz file with same jar file(pack200 tool).
HelloWorld123.gz
pack200 --gzip -E9 HelloWorld123.gz HelloWorld123.jar
HelloWorld123.jar.pack
pack200 --no-gzip -E9 HelloWorld123.jar.pack HelloWorld123.jar
HelloWorld123.jar.pack.gz
pack200 --gzip -E9 HelloWorld123.jar.pack.gz HelloWorld123.jar
and tried these files with the above html code
HTML Code:
<APPLET CODE = "HelloWorld.class" ARCHIVE = "HelloWorld123.gz" WIDTH = "200" HEIGHT = "50" >
or
HTML Code:
<APPLET CODE = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar.pack" WIDTH = "200" HEIGHT = "50" >
or
HTML Code:
<APPLET CODE = "HelloWorld.class" ARCHIVE = "HHelloWorld123.jar.pack.gz" WIDTH = "200" HEIGHT = "50" >
while loading this class I found that class loader error on sun console(as follows).
Code :
liveconnect: Invoking JS method: document
liveconnect: Invoking JS method: URL
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@23d275, refcount=1
basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@e85825
basic: Loading applet ...
basic: Initializing applet ...
basic: Starting applet ...
basic: completed perf rollup
network: Connecting [url]http://localhost:7020/designer/details/HelloWorld123.pack.gz[/url] with proxy=DIRECT
network: Connecting socket://localhost:7020 with proxy=DIRECT
network: Connecting [url]http://localhost:7020/designer/details/HelloWorld123.pack.gz[/url] with cookie "JSESSIONID=gGsmMJmbGmZhtyKTn1v2FWvcRkFhN18Dpm81R2RLM6LYvYfFLf25!-726539454"
network: Downloading resource: [url]http://localhost:7020/designer/details/HelloWorld123.pack.gz[/url]
Content-Length: 314
Content-Encoding: null
load: class HelloWorld.class not found.
java.lang.ClassNotFoundException: HelloWorld.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
basic: Exception: java.lang.ClassNotFoundException: HelloWorld.class
Ignored exception: java.lang.ClassNotFoundException: HelloWorld.class
In the About detail I can get that HelloWorld123.pack.gz or HelloWorld123.jar.gz or HelloWorld123.jar.pack.gz is downloading.
My question is will browser decompress the .gz file to .jar file internally ? or I am missing some coding for .gz file decompression ?.
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
As far as I know, the applet tag will only decompress from .jar files. Also, the Applet tag has been deprecated and the preferred method for embedding applets is via the <object> tag.
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Hi
I have tried with <object> tag, still getting same error "class not found". will <object> tag decompress .gz files in browser ?
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Quote:
will <object> tag decompress .gz files in browser
No. Its still the same browser whether you use the <applet tag or the <Object tag.
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
I used <object> tag still getting same error, can some one please send me complete working code and pack200 .gz file conversion details.
Thanks
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Where did you get the .gz file from? Ask them to give you a jar file instead. Jar files work.
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
I got .gz file after packing of .jar by pack200 tool, this will reduce the size so that we can load applets faster
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Quote:
so that we can load applets faster
How much smaller is the .gz file?
Does it load faster?
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
you will need to either:
1. Deploy the .jar.pack.gz files using a webserver and ensure that the webserver sends the header: content-encoding=pack200-gzip, or
2. write a custom class loader that will first unpack the file(s) into .jar format on the destination.
that is all...
Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser
Quote:
Originally Posted by
Norm
How much smaller is the .gz file?
Does it load faster?
pack200-gzip can reduce an archive up to about a third of its original size depending on whats in the archive (obviously already compressed resources like pictures will not get smaller)
If the size of your archives are quite big before pack200-gzip is used and your app is deployed over a slow connection (i.e. internet) then pack200-gzip can dramatically reduce download times.