> Thanks a lot for your detailed answer. I followed your
> recommendation and got my test working using reflection.
> Now I don't need to know exact names for Home/Remote
> interfaces.
> Great, but it looks like they have to be present in CLASSPATH
> anyway. Otherwise I'm getting CommunicationException:
>
> javax.naming.CommunicationException [Root exception is
> java.lang.ClassNotFoundException: UserHome]
>
> Sorry, for bothering you again, but let me ask you,
> as the master of JNDI, what I'm doing wrong?

You need to enable dynamic classloading in your client by setting a security
manager. That should fix it. (Note: this has nothing to do with JNDI, but
rather with how RMI works which is used by the JNDI implementation).

> I'm afraid I missed something about JNDI (in spite of I
> have c++/corba background).
> Does lookup() method required "looked" class to be present
> in classpath or at list to be dynamically loaded?
> Is there any other way to get an object without having it
> in classpath?

It requires the classes to be available through the semantics of
MarshalledObject.get(), which means the class must be
a) in the system classpath
b) in the thread context classloader
c) in the RMI codebase set by the one that bound the object
In this case it should be c) since you do not want to preinstall the classes
on your client (or at least it seems that way to me). c) is basically RMI
dynamic classloading, so the usual rules for that apply.

> My client looks like:
>
> [...]
> try
> {
>   InitialContext jndiContext = new InitialContext();
>
>   // here I got an exception, if UserHome interface is not in
> classpath
>   Object ref  = jndiContext.lookup("User");
>
>   Method createMethod = ref.getClass.getMethod("create",
> null);
>   Object o = createMethod.invoke(ref, null);
>
>   Method computeMethod = o.getClass()
>   .getMethod("compute",
>                                      new
> Class[]{String.class});
>
>   String xml = (String)computeMethod.invoke(o,
> new Object[]{new String("aaa")});
>   [...]
> }
> catch(Exception e)
> {
>   System.err.println( e );
>   e.printStackTrace();
> }
> [...]

Add System.setSecurityManager(new SecurityManager()); at the top and you
should be fine.

/Rickard




--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to