Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Jars inside of jars

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
fun
Asked:
fun
  • 3
  • 2
1 Solution
 
evijayCommented:
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
 
funAuthor Commented:
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
 
evijayCommented:
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
 
evijayCommented:
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
 
funAuthor Commented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now