How to use an Applet with multiple-jars

Hi everybody,

I would like to use an applet with multiple-jars.

ex:

"""

<applet codebase="." archive="main.jar,Addon1.jar,Addon2.jar" code="Appl.class" id="MyTest" width="600" height="30">

<param name = "MyParam" value = "1;2">

</applet>

"""

An applet with :

-> 1 Main JAR

-> X Addon JARs (X : a parameter "PRM")

My main part knows the parameter "PRM" -> knows which addon to use

My question is, how do I use classes from addons, inside the main part (and vise-versa if possible) ?

Thanks in advance

Best regards

[613 byte] By [Syrriusa] at [2007-11-27 10:13:58]
# 1

Try organizing the the classes under packages. Make sure that package name + class name is unique across all jars. In case you have identical class name, fully qualfy the class. Think of call to classforname with different package names based on your param.

Autmatic selection by changing the order of the Addon jars might introduce bugs that are hard to catch.

ddas_72a at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...
# 2

I try what you say :

=== HTML ===

<applet codebase="." archive="Main.jar,Addon1.jar" code="Test.Appli.class" id="MyTest" width="600" height="30">

<param name = "myPrm1" value = "1;2">

</applet>

===MAIN JAR ===

package retest;

interface InterfAddOn1 {

public void AfficheTest1(String sStrTest);

}

public class Ctest {

public Ctest() {}

public void unTest(String sClassNameR) {

String sClassName = "PackTestAddon.TestClass1";

try {

Object oObj = Class.forName(sClassName).newInstance();

((InterfAddOn1) oObj).AfficheTest1(" Hello World ");

} catch (ClassNotFoundException ex1) {

System.out.println("ERR Class not found");

} catch (IllegalAccessException ex1) {

System.out.println("ERR Illegal Access");

} catch (InstantiationException ex1) {

System.out.println("ERR Instantiation Exception");

}

}

}

===ADDON JAR ===

package PackTestAddon;

public interface InterfAddOn1 {

public void AfficheTest1(String sStrTest);

}

--

package PackTestAddon;

public class TestClass1 implements InterfAddOn1 {

public TestClass1() {}

public void AfficheTest1(String sStrTest) {

System.out.println("Test :"+sStrTest);

}

}

I have this error :

"""

Exception in thread "AWT-EventQueue-2" java.lang.ClassCastException: PackTestAddon.TestClass1

at retest.Ctest.unTest(Ctest.java:58)

at retest.Appli.actionPerformed(Appli.java:442)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

"""

I don't really know why ... =;o(

Helppppp ... Thanks in advance.

Syrriusa at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...
# 3

I don't think this solves your problem, but, I found when using multiple jar files that I had to have a space as well as a comma separating the jar files, for either Firefox or Explorer (sorry can't remember which)

ie

archive="main.jar,Addon1.jar,Addon2.jar"

would not work and needed to be

archive="main.jar, Addon1.jar, Addon2.jar"

GeoffTitmussa at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...
# 4

I try ... but no change ...

=;o(

Syrriusa at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...
# 5

Fix your class cast exception by developing java application. applets are hard to debug/test.

Your interface, InterfAddOn1 should be defined only in the main jar. Other jars will use the interface from the main jar. If you are new to java progarmming make sure that the interface is in a separate file.

ddas_72a at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...
# 6

Yes ... It works really fine =;o)

I try as you tell me :

-> Interface only in my main jar

-> Addon jar use main jar interface

Thanks a lot for your help...

Best regards

Syrriusa at 2007-7-28 15:30:19 > top of Java-index,Desktop,Core GUI APIs...