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 5 of 5

Thread: Running an Applet With JAR file

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question Running an Applet With JAR file

    Hi,
    I have created an Applet as follows and made it into a jar file (SampleApplet.jar).

    import java.applet.Applet;
    import java.awt.Graphics;
    public class SampleApplet extends Applet
    {
    public void paint(Graphics g)
    {
    	String ss;
    	Sample s=new Sample();
    	ss=s.test("From Sample Class");
    	g.drawString(ss, 20,30);
    }
     
    }

    I have created a seperate dependent class as follows and made it into a jar file (Sample.jar).

    public class Sample 
    {
    	public String test(String a)
    	{
    		System.out.println(a);
    		return a;
    	}
     
    }

    SampleApplet is depends on Sample

    I have created a HTML file as,

    HTML Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Sample Applet</title>
    </head>
    <body>
    <applet name="SampleApplet" code="SampleApplet"></applet>
    </body>
    </html>
    Now I need to run the applet just by running the HTML Page in the browser (and by having only those two jar files) . How to achieve it ?

    Please help !

    Thanks,

    Ramesh Jothimani


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Running an Applet With JAR file

    What error do you get in the browser's java console?
    Do you know about the <APPLET tag's archive= attribute?
    That should point to the jar files containing the class files you need.
    Last edited by Norm; July 19th, 2011 at 11:23 AM.

  3. The Following User Says Thank You to Norm For This Useful Post:

    rameshiit19 (July 20th, 2011)

  4. #3
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Exclamation Re: Running an Applet With JAR file

    I have modified my HTML code as follows,

    HTML Code:
    <html>
    <head>
    <title>Sample Applet</title>
    </head>
    <body>
    <applet name="sampleapplet" code="SampleApplet" archive="SampleApplet.jar" height="80" width="100" mayscript="true"></applet>
    </body>
    </html>
    My manifest file looks as follows (In SampleApplet.jar),
    Manifest-Version: 1.0
    Class-Path: C:/Sample.jar
    Created-By: 1.6.0_20 (Sun Microsystems Inc.)
    I am getting the following errors in Java Error Console:

    load: class SampleApplet.class not found.
    java.lang.ClassNotFoundException: SampleApplet.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Ramesh\Desktop\RameshWorkSpace\SampleAppl et\src\SampleApplet\class.class (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 9 more
    Exception: java.lang.ClassNotFoundException: SampleApplet.class
    load: class SampleApplet.class not found.
    java.lang.ClassNotFoundException: SampleApplet.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Ramesh\Desktop\RameshWorkSpace\SampleAppl et\src\SampleApplet\class.class (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 9 more
    Exception: java.lang.ClassNotFoundException: SampleApplet.class
    Last edited by rameshiit19; July 20th, 2011 at 02:27 AM.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Running an Applet With JAR file

    class SampleApplet.class not found.
    This output does not look like it came when you used this HTML: code="SampleApplet"
    The code= tag does not have .class after the class name.
    Where did the .class come from in the error message?

    I don't know if the browser will use the Class-path: line from the manifest file to find jar files.
    I do think it will look in jar files in the archive= attribute to use jar files.

  6. The Following User Says Thank You to Norm For This Useful Post:

    rameshiit19 (July 20th, 2011)

  7. #5
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Running an Applet With JAR file

    Found the bug.It's in manifest file.

    Specified Class-Path: C:/Sample.jar as
    Class-Path: /C:/Sample.jar
    . It's working fine now.

    Thanks !

Similar Threads

  1. Accessing an external JAR file using Applet
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 28th, 2011, 12:51 AM
  2. Applet throw ClassNotFound exception when one of the file is recompiled
    By philwei in forum What's Wrong With My Code?
    Replies: 21
    Last Post: July 12th, 2011, 01:21 PM
  3. [SOLVED] jar file Built(clean and build) perfectly, but not running as jar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: July 11th, 2011, 11:41 AM
  4. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  5. Help with running class file
    By carface in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 30th, 2010, 05:40 PM