Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jars inside of jars

Posted on 1998-05-29
5
Medium Priority
?
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 300 total points
ID: 1221704
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
ID: 1221705
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
ID: 1221706
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
ID: 1221707
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
ID: 1221708
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

730 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