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: Accessing an external JAR file using Applet

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

    Question Accessing an external JAR file using Applet

    Hi,
    I have created an applet as follows.

    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 also made it as a JAR using,

    jar -cf SampleApplet.jar SampleApplet.class
    I have created the dependent class as,

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

    }
    I have created the jar of the above class using ,

    jar -cf Sample.jar Sample.class
    I need Sample.jar to be embedded into SampleApplet.jar and want to run "SampleApplet.jar" as stand alone ...

    I wrote the HTML code as,
    <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>
    Please help !

    Thanks,
    Ramesh Jothimani


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Accessing an external JAR file using Applet

    I need Sample.jar to be embedded into SampleApplet.jar and want to run "SampleApplet.jar" as stand alone ...
    Can you explain what "embedded" means?
    Any file can be added to a jar file. You can add Sample.jar to the SampleApplet.jar file. No idea what good that is, but it can be done.

    run "SampleApplet.jar" as stand alone
    By standalone, I assume you want to execute the program outside of a browser and without HTML.
    Set that jar up as an executable jar. It needs a manifest file with a Main-Class: line that points to a class with a main() method.
    Last edited by Norm; July 18th, 2011 at 10:11 AM.

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

    Question Re: Accessing an external JAR file using Applet

    Quote Originally Posted by Norm View Post
    Can you explain what "embedded" means?
    Any file can be added to a jar file. You can add Sample.jar to the SampleApplet.jar file. No idea what good that is, but it can be done.


    By standalone, I assume you want to execute the program outside of a browser and without HTML.
    Set that jar up as an executable jar. It needs a manifest file with a Main-Class: line that points to a class with a main() method.
    I need to add Sample.jar in SampleApplet.jar & I meant it as embedded .

    Thanks !

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Accessing an external JAR file using Applet

    add Sample.jar in SampleApplet.jar
    You can use the jar command will add the Sample.jar file to the SampleApplet.jar
    Why do you want to do that? You will not be able to execute class files contained in the Sample.jar file while it is in another jar file.

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

    rameshiit19 (July 28th, 2011)

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

    Default Re: Accessing an external JAR file using Applet

    That was the requirement I got Not they have accepted in making two independent jars and is working fine . Thanks !

Similar Threads

  1. 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
  2. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  3. Running a external exe in Mac OS
    By supertreta in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 15th, 2010, 01:32 PM
  4. Interaction with external application
    By righi in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 2nd, 2010, 08:37 AM
  5. Accessing Properties File
    By java_mein in forum Java Servlet
    Replies: 5
    Last Post: May 14th, 2010, 02:44 AM