Solved

Jars inside of jars

Posted on 1998-05-29
5
333 Views
Last Modified: 2013-11-23
If I have a bean packaged in a jar file, can I put this jar file inside another to package an applet. I have a bean DC.class packed into DC.jar. I then have an applet Date.class that uses bean DC. If I pack Date.class, other needed classes, and bean DC.jar into Date.jar will this work? How would my applet look? What would my manifest file look like?
0
Comment
Question by:fun
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 100 total points
Comment Utility
First let us understand how Beans.instantiate works.

Beans.instantiate is used to create beans in client programs. First parameter is the name of class loader that will create your bean (pass null if you dont have one). Second parameter specifies name of bean. Here is the important point.

   The filename can be a fully qualified class name or the name of a ser file that contains a serialized version of the bean.

   The instantiate method tries to load a serialized object with that name. If it fails, it looks fro a class with the same name and then uses it to create an instance of a bean. Now let us go to your question.

>  If I pack Date.class, other needed classes, and bean DC.jar into Date.jar will this work?

Ans: No. It doesnt. The Date applet when it instantiates the bean, it looks for a .ser file or a .class file by name DC.class or DC.ser in the Date.jar archive. It will not find it and hence will give class not found error. Notice that the class file is in DC.jar but the class loader doesnt know this. It treats a jar file within a jar file as any other ordinary file.

>  How would my applet look ?
The proper way of doing this is Have DC.jar seperate. create a jar file Date.jar containing a single fle Date.class. Now, the html applet tag should have the following structure

<applet code=Date.class archive=Date.jar,DC.jar
        Width=100  height=100>

The DC.jar will have the manifest file which is as it is provided by bean provider. The Date.jar has a manifest file with ordinary default entries created by the jar tool.

Note that the DC.jar file has special manifest entries only for describing the contents of a jar. If the jar contains a bean file, it has entry Java-bean=true and this info is interpreted by the visual tool (like symantec cafe, openj builder etc.,.) not by the java vm. It is the visual tool which makes use of the manifest file to identify the beans in a jar and other info about that beans. It is not the java vm or java interpreter which makes use of the jar entris.
0
 
LVL 1

Author Comment

by:fun
Comment Utility
I have tried your suggestion and it still doesn't work quite right. What happens is this, if I try to use both jar files, the applet will load but the bean functions don't work. However, if I include the bean as a naked class file dc.class alongside the Date.jar then it works fine. I am wondering if this could have anything to do with "Activator"? It's as if activator can see the class file in DC.jar but can't properly load it or access it if it is inside a jar. I am using NN4.04 with th activator plugin and have converted my html with the program supplied by Sun. I even tried to insert DC.class into Date.jar and it still does the same thing.
Have you ever built an applet that uses a separate bean to do something? None of my books actually go through all the steps to create such a project.
0
 
LVL 4

Expert Comment

by:evijay
Comment Utility
Hey,

Did you ever use beanbox (in bdk) completely. It has in File menu an option called Make Applet. This packages your designed application using beans into a jar and generates everything for you. Just try it out. Please use Netscape communicator 4.05 for i found some problem with 4.04. Netscape 4.05 comes with the jdk1.1 support and no patch is required.

here is another full fledged applet which i tried in my browser before answering my question.
It requires swing-1.0.2 package however !!

 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
                      <!-- @(#)SwingApplet2.html 1.1 97/07/02 -->
                      <html>
                      <head><title>Swing Applet</title></head>
                      <body> <applet code=SwingApplet2.class Archive=test.jar,swingall.jar width=500 height=300>
                      </applet>
                      </body>
                      </html>

              Where SwingApplet.java is

              import java.awt.*;
                               import java.awt.event.*;
                               import java.net.*;
                               import java.applet.*;
                               import com.sun.java.swing.*;

                               public class SwingApplet extends JApplet {

                                   JComboBox combobox;

                                   public void init() {

                               // Force SwingApplet to come up in the System L&F
                               String laf = UIManager.getSystemLookAndFeelClassName();
                               try {
                                   UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                               } catch (UnsupportedLookAndFeelException exc) {
                                   System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
                               } catch (Exception exc) {
                                   System.err.println("Error loading " + laf + ": " + exc);
                               }

                                       getContentPane().setLayout(new FlowLayout());
                                       combobox = new JComboBox();
                                       combobox.setEditable(true);
                                       getContentPane().add(combobox);
                                   }

                                   public void stop() {
                                       if (combobox != null) {
                                           getContentPane().remove(combobox);
                                           combobox = null;
                                       }
                                   }

                                    public static void main(String args[]) {
                                        SwingApplet applet = new SwingApplet();
                                        applet.init();
                                        JFrame frame = new JFrame();
                                        frame.setBounds(0,0,500,300);
                                        frame.getContentPane().add(applet);
                                        frame.show();
                                        return;
                                    }
                               }

Try the beanbox thing and if you still find problem, contact me.

0
 
LVL 4

Expert Comment

by:evijay
Comment Utility
I am sorry that i gave you wrong java program
here is correct one



        import java.awt.*;
        import java.awt.event.*;
        import java.net.*;
        import java.applet.*;
        import com.sun.java.swing.*;

        public class SwingApplet2 extends JApplet {

            JComboBox combobox;

            public void init() {

        // Force SwingApplet to come up in the System L&F
        String laf = UIManager.getSystemLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException exc) {
            System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
        } catch (Exception exc) {
            System.err.println("Error loading " + laf + ": " + exc);
        }

                getContentPane().setLayout(new FlowLayout());
                combobox = new JComboBox();
            combobox.addItem("HelloWorld!!");
            combobox.addItem("HelloWorld!!2");
                combobox.setEditable(true);
                getContentPane().add(combobox);
            }

            public void stop() {
                if (combobox != null) {
                    getContentPane().remove(combobox);
                    combobox = null;
                }
            }
        }



0
 
LVL 1

Author Comment

by:fun
Comment Utility
What I am really looking for is an example of an applet that uses a bean and uses "Activator" to run. Your example is just extending a swing class. I appreciate your help though.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now