Do I have to create proxies for every class used by the JVM?

83 views
Skip to first unread message

James

unread,
Feb 22, 2012, 8:05:54 AM2/22/12
to jni4net
Hello,

I am trying to call a single method from my own Java API, which is in
a jar file (e.g. james.jar). Is it possible to do this by reflection,
using the proxies that come with jni4net, so that I don't have to
create proxies for the jar?

var bs = new BridgeSetup(false);
// location of james.jar and jni4net.j-0.8.6.0.jar
bs.AddAllJarsClassPath("C:\\Users\\james\\Desktop\\lib\\");
bs.AddAllJarsClassPath(".");
Bridge.CreateJVM(bs);

The above code completes normally, and I am able to print hello world:

java.lang.System.@out.println("Hello world")

However, if I do this:

java.lang.Class.forName("james.TestClass");

I get a ClassNotFoundException. So my question is: Does every class
used by the JVM require a proxy, or am I doing something wrong?

Thanks for any help.

Pavel Šavara

unread,
Feb 22, 2012, 11:24:51 AM2/22/12
to jni...@googlegroups.com
On Wed, Feb 22, 2012 at 5:05 AM, James <james....@gmail.com> wrote:
Hello,

I am trying to call a single method from my own Java API, which is in
a jar file (e.g. james.jar). Is it possible to do this by reflection,
using the proxies that come with jni4net, so that I don't have to
create proxies for the jar?

Yes.
 

 var bs = new BridgeSetup(false);
 // location of james.jar and jni4net.j-0.8.6.0.jar
 bs.AddAllJarsClassPath("C:\\Users\\james\\Desktop\\lib\\");
 bs.AddAllJarsClassPath(".");
 Bridge.CreateJVM(bs);

The above code completes normally, and I am able to print hello world:

 java.lang.System.@out.println("Hello world")

However, if I do this:

 java.lang.Class.forName("james.TestClass");

Most likely something is wrong with  classPath. Try to add absolute path to jar file rather.
LIke this
 bs.AddClassPath("C:\MyTest\james.jar");

You could also try another classLoader()

ClassLoader.getSystemClassLoader().loadClass()
just in case


 
I get a ClassNotFoundException. So my question is: Does every class
used by the JVM require a proxy
No, proxy is just API for CLR side, has nothing to do with JVM behavior itself.

 
, or am I doing something wrong?

Thanks for any help.

Cam Hoang Truc

unread,
Feb 28, 2012, 2:57:36 AM2/28/12
to jni4net
Hi Pavel Šavara,
How can I do to add a dll file in Java and get a class of this dll
like the way you do in C# .
Thanks in advance.

Reply all
Reply to author
Forward
0 new messages