all groups > vj# > december 2003 >
You're in the

vj#

group:

j# Browser Control Class.forName


j# Browser Control Class.forName udi NO[at]SPAM netmanage.co.il
12/31/2003 4:46:50 AM
vj#:
Hello,
We are trying to migrate a very very big project from Java Applets to
JBC.
I'm haveing bad time with Class.forName. What ever I try (even in very
simple demo) I just keep getting "ClassNotFound" exceptions.

I've read all the articals but I just cannot get it to work.

Any Ideas?

Thanks,
Udi Zisser
Netmanage Inc.
udi@netmanage.co.il
Re: j# Browser Control Class.forName Bart Jacobs
1/1/2004 3:53:45 PM
Udi,

I have tried the "very simple demo" below:

==== Begin PlugIn.java =================================================

package test;

public interface PlugIn {
void run(TestApplet applet);
}

==== End PlugIn.java ===================================================

==== Begin TestApplet.java =============================================

package test;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class TestApplet extends Applet {
Label label;
public int counter;

public void init() {
label = new Label("0");
add(label);

Button button = new Button("Go");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
go();
}
});
add(button);
}

void go() {
try {
Class plugInClass = Class.forName("test.TestPlugIn");
PlugIn plugInObject = (PlugIn) plugInClass.newInstance();
plugInObject.run(this);
label.setText(String.valueOf(counter));
} catch (Exception ex) {
label.setText(ex.toString());
}
}
}

==== End TestApplet.java ===============================================

==== Begin TestPlugIn.java =============================================

package test;

public class TestPlugIn implements PlugIn {
public void run(TestApplet applet) {
applet.counter++;
}
}

==== End TestPlugIn.java ===============================================

It runs perfectly on my system. Does it also run on your system?

If so, how does your very simple demo differ from this one?

Greetings

Bart Jacobs
Re: j# Browser Control Class.forName Bart Jacobs
1/1/2004 4:20:44 PM
Udi,

In my previous posting, I forgot to mention a very important point: I
compiled all three classes into the same assembly. That is, I used the
following compiler command:

vjc /target:library /out:TestApplet.dll *.java

The demo works only if TestPlugIn and TestApplet are in the same
assembly. This is because the J# version of Class.forName(String) looks
only in the assembly that contains the call of Class.forName.

If you want to load the plug-in from a different assembly, say
TestPlugIn.dll, then use the following code:

Class plugInClass =
Class.FromType(System.Type.GetType("test.TestPlugIn, TestPlugIn"));

and compile the demo as follows:

vjc /t:library /out:TestApplet.dll PlugIn.java TestApplet.java
vjc /t:library /out:TestPlugIn.dll /r:TestApplet.dll TestPlugIn.java

Greetings

Bart Jacobs
Re: j# Browser Control Class.forName udi NO[at]SPAM netmanage.co.il
1/4/2004 12:21:32 AM
Thanks for the reply.
when we use Class.forName most of the time we will use it like the
second post. So I guess I have to read some more about
"Class.FromType".
Anyway, I've managed to get it to work using statments like:
Class tempClass = Class.forName("http://localhost/test/MFDharness.dll",param,true);

I still can't get the JBC to locate the .dll using the app.config file
(probing or appdomain)

Thanks,
Udi Zisser
NetManage Inc.

------
[quoted text, click to view]
AddThis Social Bookmark Button