Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: Embedding JAR in html.

  1. #1
    Join Date
    May 2011
    Location
    Seattle, WA
    Posts
    35
    Rep Power
    0

    Default Embedding JAR in html.

    I've successfully created a runnable JAR file. Now I'm trying to embed it into html.
    I can run it fine by just clicking on the the file, but I'm having trouble running it on my webpage.

    Here is the source code if its of any relevance:

    Java Code:
    package donut;
    
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    
    import javax.swing.JPanel;
    
    
    public class Board extends JPanel{
    	
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		Graphics2D g2 = (Graphics2D) g;
    		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
    											RenderingHints.VALUE_ANTIALIAS_ON);
    		
    		rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    		g2.setRenderingHints(rh);
    		Dimension size = getSize();
    		double w = size.getWidth();
    		double h = size.getHeight();
    		
    		Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
    		g2.setStroke(new BasicStroke(1));
    		g2.setColor(Color.gray);
    		
    		for(double deg = 0; deg < 360; deg += 5)
    		{
    			AffineTransform at = AffineTransform.getTranslateInstance(w/2, h/ 2);
    			at.rotate(Math.toRadians(deg));
    			g2.draw(at.createTransformedShape(e));
    		}
    		
    	}
    	
    	public Board()
    	{
    		
    	}
    
    }
    Java Code:
    package donut;
    
    import javax.swing.JFrame;
    
    public class Donut extends JFrame{
    
    	public Donut()
    	{
    		add(new Board());
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(360, 310);
    		setLocationRelativeTo(null);
    		setTitle("Donut");
    		setVisible(true);
    	}
    	
    	public static void main(String[] args)
    	{
    		new Donut();
    	}
    	
    }
    Here is what it does:
    Embedding JAR in html.-ejih1.png

    But when I try to run it on my webpage I get this:
    Embedding JAR in html.-ejih2.png

    Here are the aforementioned "details" of the previous image:
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    load: class Donut.class not found.
    java.lang.ClassNotFoundException: Donut.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)
    Exception: java.lang.ClassNotFoundException: Donut.class
    And finally here is the HTML code I used to embed it:
    <APPLET ARCHIVE="donut.jar"
    CODE="Donut.class"
    WIDTH=360
    HEIGHT=310>
    </APPLET>


    If you require any additional information I will provide it as soon as possible.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Embedding JAR in html.

    Your class Donut is a JFrame, not an Applet. Make it a (J)Applet.
    Lesson: Java Applets (The Java™ Tutorials > Deployment)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Join Date
    May 2011
    Location
    Seattle, WA
    Posts
    35
    Rep Power
    0

    Default Re: Embedding JAR in html.

    I am now using JApplet instead of JFrame, however I'm having the same error.
    Here is my new source:
    Java Code:
    package donut;
    
    import java.applet.Applet;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    
    
    public class Board extends JApplet{
    	
    	public void init()
    	{
    		add(new Board());
    		setSize(360, 360);
    		setVisible(true);
    	}
    	
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		Graphics2D g2 = (Graphics2D) g;
    		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
    											RenderingHints.VALUE_ANTIALIAS_ON);
    		
    		rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    		g2.setRenderingHints(rh);
    		Dimension size = getSize();
    		double w = size.getWidth();
    		double h = size.getHeight();
    		
    		Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
    		g2.setStroke(new BasicStroke(1));
    		g2.setColor(Color.gray);
    		
    		for(double deg = 0; deg < 360; deg += 5)
    		{
    			AffineTransform at = AffineTransform.getTranslateInstance(w/2, h/ 2);
    			at.rotate(Math.toRadians(deg));[QUOTE][/QUOTE]
    			g2.draw(at.createTransformedShape(e));
    		}
    		
    	}
    	
    	public static void main(String args)
    	{
    		
    	}
    
    }
    Also, here is my manifest file:
    Manifest-Version: 1.0
    Created-By: 1.6.0 (Sun Microsystems Inc.)
    Main-Class: donut.Board

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Embedding JAR in html.

    Assuming your applet tag is the same I'm not surprised...your applet is donut.Board, not Donut.
    DarrylBurke likes this.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Embedding JAR in html.

    A jar for an Applet doesn't require a Main-Class. The class to be run is read from the HTML tag.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. embedding a unix terminal
    By slichy in forum Advanced Java
    Replies: 3
    Last Post: 06-30-2011, 04:36 PM
  2. Embedding applet into HTML
    By vin_eets in forum AWT / Swing
    Replies: 3
    Last Post: 03-22-2011, 01:05 PM
  3. Embedding Database
    By shalin.shah in forum JDBC
    Replies: 1
    Last Post: 12-12-2010, 06:40 AM
  4. Netbeans 6.5.1 & embedding in html page
    By dbashby in forum New To Java
    Replies: 5
    Last Post: 04-06-2009, 03:58 AM
  5. Embedding Applet into HTML?
    By Unome in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •