Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Java Applet Development - pack200 .gz file unpack and create .jar file in browser.

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

      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).

    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 ?.
    Last edited by maheshsardar; August 3rd, 2010 at 06:40 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,048
    Thanks
    47
    Thanked 2,143 Times in 2,116 Posts

    Default Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser

    will <object> tag decompress .gz files in browser
    No. Its still the same browser whether you use the <applet tag or the <Object tag.

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser


  6. #6
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,048
    Thanks
    47
    Thanked 2,143 Times in 2,116 Posts

    Default 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.

  8. #8
    Junior Member
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,048
    Thanks
    47
    Thanked 2,143 Times in 2,116 Posts

    Default Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser

    so that we can load applets faster
    How much smaller is the .gz file?
    Does it load faster?

  10. #10
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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...

  11. #11
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet Development - pack200 .gz file unpack and create .jar file in browser

    Quote Originally Posted by Norm View Post
    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.

Similar Threads

  1. Create a file specifying the size JAVA
    By Harbox in forum Java Theory & Questions
    Replies: 3
    Last Post: September 20th, 2012, 10:30 AM
  2. How to change File Type of a File Using java
    By akash169 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 31st, 2010, 02:58 AM
  3. Facing problem with posting Excel file for download - Content in browser
    By ragz_82 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 9th, 2010, 07:28 AM
  4. create a file
    By mos33 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 4th, 2009, 01:21 PM
  5. How to create exe file
    By sirimalla in forum Java Theory & Questions
    Replies: 6
    Last Post: November 1st, 2009, 03:07 AM