RMI Classloading and referenced classes

Hi All,
I am trying to develop an application that uses a thin client methodology using RMI. What I mean by thin client is that there will only be several classes to start the client side application and invoke the rmi server. The rmi server will return the class files (mainly Swing/Charva JFrame and JPanel classess, which I refer to as the UI classes), which will be instantiateds and referenced by an interface that all the classes implement. Many of the UI classes also instantiate classes for control and presentation (i.e. extended JText Fields and other java classes). It seems that because RMI uses the URLClassLoader, the referenced class types do not have to reside on the client side on disk. I believe this is because RMI automatically loads both the classes that were requested by the client and any additional classes that are referenced by the requested classes. My first question is:
1. Are the referenced classes loaded at the same time the called class is loaded, or when the called class is instantiated?
2. We store the rmi requested .class files in a hash table the first time they are requested. We do this so we do not need to go accross the network the next time we need to reference and instanitiate the class; we just get if from the hash table. My question is, if we instantiate the class file from the hash table, does RMI reload the referenced class files (the classes that are instantiated within the object I am instantiating, i.e Extended JText and UI Controller classes) from the RMI server or are the loaded from memory on the client side?
Any responses are greatly appreciated.
Elliott Gonshor
QuestDiagnostics

Hi,
I remembered that some of the AWT components have
their corresponding Serializable form. I am not too sure
if Swing components has such a form. But since you
have make it happened, I think that it should be yes.
I found some words in the book, Java Enterprise in a
Nutshell. I excerpt some of them in the book as follows :
========================
java Djava.server.rmi.codebase=-http://objhost.org/classes/ Regaccount
We've setting the codebase to http://objhost.org/classes/,
so we have to make sure that an htpp server is running on
the objhost.org machine and that the necessary class files
(eg, the AccountImpl stub class) are in the classes
directory of that http server's document root
Now we can run the AccountClient class on the remote
client as before, but the client's host machine doesn't
have the stub class for the Account remote object
available locally. WHEN THE AccountClient TRY TO
LOOK UP THE REMOTE Account OBJECT, we want
the stub class to be loaded remotely. ......................
===================================
You may notice that I uppercase one sentence !
So if I believe the description, then I think those
referenced class files should be loaded when the
called class is instantiated. Since it happens at the
time when the action of look it up.
Since it has been load into the client, I think that it should
loaded those reference class on the client side. Although
it just said that
but the client's host machine doesn't
have the stub class for the Account remote object
available locally. ...........
it seems to mean that it does not have it locally so it
start loading it from remote. So it might be the case if
it existed in local, it should be cached and without
reloaded from remote.
It is my assertion. I could not promise ii it is right
or not. In fact, Try it might be better.
For the first question, you may try to insert some
flag in the code which is downloaded firstly and
observe if it happen in which phase, loaded at
the same time, or when the called class is instantiated
For the second question, You may try to make it
work, that is, all classes have been downloade to
the client side and works smoothly. Consider that
remove those reference class file stored in the remote
side. and request again.
if it works, it means that local class is reference firstly.
if not, it means that it reloaded from the remote side
without considering the copy in local.
if all of them are wrong , Well ..... God bless you !
hahaha
good luck,
Alfred Wu

Similar Messages

  • Java stored procedures and referencing classes

    We are referencing to some classes/libraries which are not present in the database. In normal java world, you specify the libraries/classes needed to run your piece of code in the CLASSPATH and that forms part of your complete code.
    Can java stored procedures in the database refer to libraries or class files it requires on the file system rather than the database? Is it possible to make this happen?
    Thanks

    pshiva,
    Posting the same question to multiple forums usually doesn't increase your chances of getting an answer, and it just frustrates those wishing to answer you with the result being that any future questions you post may have less chance of being answered -- because of your uncourteous, initial behaviour.
    I have answered your other thread:
    java stored procedures and referencing classes
    In my opinion, that forum (the Database JVM forum) is the most appropriate for your question.
    Good Luck,
    Avi.

  • GetResources() gives null's after using RMI (ClassLoader problem???)

    Hi
    I have just put RMI into my app and it works fine, connects to a remote server, runs a method on the server and returns the results.
    The problem is when I try to use a line like:
    URL url = MyClass.class.getResources("image/save.gif");
    The url is null. This code will work before my RMI function is run. Also, every dialog the application opens after running RMI has a line at the top of the pane saying: "Java Applet Window".
    Is RMI playing with the Classloader?
    Do I have to instaniate the ClassLoader or do something else to get my resources again and get rid of the text on each of the dialog boxes???
    Thanks in advance.

    if your class is Remote object, you use the RMI CLassLoader when you do:
    URL url = MyClass.class.getResources("image/save.gif");you shoud use instead:
    URL url = Classloader.getSystemResources("image/save.gif");

  • Dynamic classloading and incompatibleclasschangeerror

    I have different versions of my applications like v1 v2 v3 and my current version is v4.
    In my case, v4 might need to talk to v3, v2 or v1. To achevie that I need that same versions of classes from the respective versions of the applications i.e. I will make jars like v3.jar, v2.jar and v1.jar which will be loaded dynamically using my own custom class loaders. When v4 trying to access v3 it uses the classes using the classloader which loaded v3.jar
    v4 contacts v3, v2, v1 through RMI.
    Now the problem is when v4 is calling a remote method of v3 I am getting IncompatibleClassChangeError
    I tried to recompile all the required classes in v3 and created a new v3.jar and I have loaded the same dynamically in v4. I also recompiled all the classes of v4, but still the result is same.
    Both v3 classes and v4 classes are compiled using the same JRE version.
    Can somebody help me to figure out what could be the issue.
    Thanks

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • RMI classloading mechanism:unable to bind an object

    hai all,
    I am facing a problem when i use rmi classloading mechanism.
    I am using suns ClassFileServer to load classes dynamiclly into my server and client.
    In my server i want to load the class and and get a static object of the same class and bind it to registry so that clents can access it.
    but i am unable to do that.
    I have a doubt regarding what happens to the static variables when class loading is done.

    I am posting my validateImpl and DynamicServer here .please look into it
    validateImpl.java:
    import java.io.FileInputStream;
    import java.io.PrintStream;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.*;
    public class validateImpl extends UnicastRemoteObject
    implements validate
    public static validateImpl getInstance()
    return validateInst;
    public validateImpl()
    throws RemoteException
    System.out.println("Inside validateimpl constructor");
    try
    Naming.rebind(new String("myserverObj"), this);
    catch(Exception exception)
    System.out.println("Exception occurred: " + exception);
    public boolean validateUser(String s, String s1)
    System.out.println("user name"+s);
    String s2 = propFile.getProperty(s);
    System.out.println("from records /t"+s2);
    if(s2 == null)
    String s3 = " User Name: " + s + " is Not Configured \n";
    System.out.println("username not found");
    StringTokenizer stringtokenizer = new StringTokenizer(s2, "~");
    PFusername = (String)stringtokenizer.nextElement();
    PFpassword = (String)stringtokenizer.nextElement();
    return PFusername.equals(s) && PFpassword.equals(s1);
    private static Hashtable cache;
    private static String PFusername;
    private static String PFpassword;
    private static Properties propFile;
    private static validateImpl validateInst;
    static
    propFile = new Properties();
    try
         System.out.println("In Static Block");
    validateInst = new validateImpl();
    propFile.load(new FileInputStream("usersandpasswords.properties"));
    catch(Exception exception)
    System.out.println("Exception in creating an instance" + exception);
    DynamicServer.java
    import java.rmi.Naming;
    import java.rmi.Remote;
    import java.rmi.RMISecurityManager;
    import java.rmi.server.RMIClassLoader;
    import java.util.Properties;
    public class DynamicServer {
    public static void main(String args[]) {
    // Create and install a security manager
    if (System.getSecurityManager() == null) {
    System.setSecurityManager(new RMISecurityManager());
    try {
    Properties p = System.getProperties();
    String url = p.getProperty("java.rmi.server.codebase");
    Class serverclass = RMIClassLoader.loadClass(url, "validateImpl");
    Naming.rebind("/myserverObj", (Remote)serverclass.newInstance());
    /*here is the problem.instead of creating a newInstance i want to bind thevalidateinstance in validateImpl class to be bound to the registry.
    but how can i access it.*/
    System.out.println("HelloServer bound in registry");
    } catch (Exception e) {
    System.out.println(e);
    }

  • Can I put both RMI server and client in a same program

    hi everybody...
    I wanna know that can I use RMI server and client in a same program....My idea is like that I wanna use the same program for client and server....When I open my program, I can accept connection from other program and if I want to connect to others, I can also connect it. I expect you to understand my question. Here are the sample code for my program...
    package Chat.Rmi;
    import java.lang.*;
    import java.util.*;
    import java.rmi.*;
    import javax.swing.*;
    import java.net.*;
    import java.rmi.server.*;
    import java.rmi.registry.*;
    public class netKitManager implements netKitInterface{
        public netKitManager(){
            try{
            reg = LocateRegistry.createRegistry(4242);
            reg.rebind("NetKitServer",this);
            }catch(RemoteException re){
        public void DirectConnect(String ip){
            try{
            netUser = (netKitInterface) Naming.lookup("rmi://"+ip+":4242/NetKitServer");
            JOptionPane.showMessageDialog(null,"Connection succeded!");
            }catch(NotBoundException nbe){
                JOptionPane.showMessageDialog(null,"There is no server at specified IP address!");
            }catch(MalformedURLException mue){
                JOptionPane.showMessageDialog(null,"IP adress may be wrong!");
            }catch(RemoteException re){
                JOptionPane.showMessageDialog(null,"Remote exception occured!");
        public void SendMessage(String msg){
            try{
            netUser.SetMessage(msg);
            }catch(RemoteException re){
        public void SetMessage(String msg) throws RemoteException{
            chatKit.SetMessage(msg);
        private netKitInterface netUser;
        private Hashtable netUserList;
        private Registry reg;
    }

    Yes it can be done. I have done it.

  • J2EE Packaging and manifest Class-Path:

    Does anyone know if Weblogic 6.0 supports the redefined deployment extension mechanism
    that makes use of the 'Class-Path:' entry in the manifest files?
    In our project we have one single .ear file containing a couple of EJB's (.jar
    files) and a Web Application (.war file).
    We are using log4j as logging mechanism and we would like to keep everything in
    the .ear file so that we can make hot-deploys. So we are trying not to make use
    of the classpath in startWebLogic.sh. All of our EJB's and the Web Application
    makes use of log4j.jar. My question is; can I do the following and make it work
    in Weblogic 6.0?
    1. In every EJB .jar file I add the follwing to the manifest file - "Class-Path:
    log4j.jar"
    2. I place the log4j.jar in the root directory of the .ear file.
    By doing this I expect that the ear classloader loads the log4j.jar classes. Am
    I right or do I do something wrong. At least it does not seem to work.
    Using Weblogic 6.0 without service pack.
    Thanks,
    Steen

    This does not work in WebLogic 6.0. It's supposed to be supported in 6.1
    Daniel
    -----Original Message-----
    From: Steen Laursen [mailto:[email protected]]
    Posted At: Wednesday, August 08, 2001 1:32 PM
    Posted To: environment
    Conversation: J2EE Packaging and manifest Class-Path:
    Subject: J2EE Packaging and manifest Class-Path:
    Does anyone know if Weblogic 6.0 supports the redefined
    deployment extension mechanism
    that makes use of the 'Class-Path:' entry in the manifest files?
    In our project we have one single .ear file containing a
    couple of EJB's (.jar
    files) and a Web Application (.war file).
    We are using log4j as logging mechanism and we would like to
    keep everything in
    the .ear file so that we can make hot-deploys. So we are
    trying not to make use
    of the classpath in startWebLogic.sh. All of our EJB's and
    the Web Application
    makes use of log4j.jar. My question is; can I do the
    following and make it work
    in Weblogic 6.0?
    1. In every EJB .jar file I add the follwing to the manifest
    file - "Class-Path:
    log4j.jar"
    2. I place the log4j.jar in the root directory of the .ear file.
    By doing this I expect that the ear classloader loads the
    log4j.jar classes. Am
    I right or do I do something wrong. At least it does not seem
    to work.
    Using Weblogic 6.0 without service pack.
    Thanks,
    Steen

  • Authorization error for referenced class javax/mail/Session.

    All,
    I am trying to compile a java source which is using session object in javax/mail/session.
    I am getting the error java/lang/System: Authorization error for referenced class javax/mail/Session.
    I used "import javax.mail.*;" in my java source..
    I loaded both mail.jar and activation.jar using the below command in different schema other than the schema which above java source exists.
    loadjava -thin -verbose -user <user>/<pwd>@<dburl> -resolve -synonym activation.jar
    loadjava -thin -verbose -user <user>/<pwd>@<dburl> -resolve -synonym mail.jar
    After loading, All java classes in mail.jar and activation.jar were in compiled state in that schema
    Its working well in different database having the same configuration.
    My oracle version is Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production

    I have to accomplish tried in CONSOLE TestMail.class:
    C>java TestMail
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Partmy make.bat:
    javac -g -classpath
    ...\Java\jre1.5.0_06\lib\activation.jar;...\jre1.5.0_06\lib\imap.jar;...\jre1.5.0_06\lib\mail.jar;...\jre1.5.0_06\lib\mailapi.jar;...\jre1.5.0_0\lib\plugin.jar;...\jre1.5.0_06\lib\pop3.jar;...\jre1.5.0_06\lib\smtp.jar;...\jre1.5.0_06\lib\javamail-1_3_2-src-jrl.zip;...\jre1.5.0_06\lib\j2ee.jar  TestMail.javaWhat isn't correct?
    Tanks,
    Mohammad

  • RMI Server and RMI Client Problem

    First, Hi!
    I have create my RMI Server and a RMI Servlet client.
    I can run the server and servlet first time and it works fine.
    Then, I stop rmiregistry and server.
    Then, I start rmiregistry and server for a second time but my RMI Servlet client gets a
    java.rmi.ConnectException: Connection refused to host: xxx.xxx.xxx.xxx; nested exception is: java.net.ConnectException: Connection refused
    If I copy the class again where the servlets resides, it works again. But I have to keep doing that. I have to keep copying the class file to the servlet directory every 2nd time I try to run it for it to work.
    Anyone know what am I doing wrong?

    First, Hi!
    I have create my RMI Server and a RMI Servlet client.
    I can run the server and servlet first time and it
    works fine.
    Then, I stop rmiregistry and server.
    Then, I start rmiregistry and server for a second time
    but my RMI Servlet client gets a
    java.rmi.ConnectException: Connection refused to host:
    xxx.xxx.xxx.xxx; nested exception is:
    java.net.ConnectException: Connection refused
    If I copy the class again where the servlets resides,which class file ? u mean RMIServer's class files ??
    I have faced the same problem too. In my case if i just restart my Tomcat webserver the error goes and the servlet is very well able to connect back to the RMI Server
    it works again. But I have to keep doing that. I have
    to keep copying the class file to the servlet
    directory every 2nd time I try to run it for it to
    work.
    Anyone know what am I doing wrong?

  • Classloader: linking a class

    Hi,
    I'm trying to manipulate the class loader to obtain something "strange". Imagine that you've got:
    public class A
    public class B extends A
    and a class that is the application
    public class APPLICATION extends A
    Now the class A is a library class an the class B is a new version of the same class.
    Imagine that the application could run on system where only A is presents and on system
    where both A,B are presents. If B is present extending B is better, but if I write:
    public class APPLICATION extends B
    where B is not present the application could not run.
    My question is: can I decide what class to extends at the loading time?
    An answer could be "recompile". Infact I can test which class is presents and recompile the application
    class setting what class to extends, but I don't want to recompile.
    An other idea is this: to load the class the system must instatiate base class first, then
    the application class. If I can decide what class to load as base class I've reached the goal!
    But the class loader (java.lang.classloader) doesn't allow user to ridefine the linking method
    (that is resolveclass) because it's native. The only method to define is loadclass but nothing about linking
    classes is made by this method.
    How can I solve this matter?
    Thanks

    Rather than manipulate the classloader to deal with dynamic inheritance, why not utilize composition instead?
    Let your application class contain an object of class a as well as an object of class b. when you try to instantiate b, if it doesn't exist, trap the NoClassDefFoundError, and instantiate a instead.
    will that get you where you need to be?

  • Obtain referenced classes from 1.6' javax.tools.JavaCompiler

    Hi,
    I'd like to use JavaCompiler both to compile .java source files and to maintain dependency information in one go. How do I obtain a list of referenced classes (or even methods, fields, etc) after/during compilation?
    Thanx in advance
    Oliver

    Thanks for the answer... I don't know how to refer to the jre path from within web start. I have solved problem ii) by passing a -cp option to the compiler. Here it is a sample code:
              ClassLocader cl = OnTheFlyCompiler.class.getClassLoader();
              List<URL> classpath = new ArrayList<URL>();
              if ( cl instanceof URLClassLoader ) {
                   URLClassLoader cl2 = (URLClassLoader)cl;
                   for (URL jar : cl2.getURLs()) {
                        classpath.add(jar);
              String classPath = System.getProperty("java.class.path");
              for (String path : classPath.split(File.pathSeparator)) {
                   try {
                        classpath.add(new URL("file:"+path));
                   } catch (MalformedURLException e) {
                        System.err.println("Wrong url: "+e.getMessage());
                        e.printStackTrace();
              StringBuffer sb = new StringBuffer();
              for (URL jar : classpath) {
                   sb.append(jar.getPath());
                   sb.append(File.pathSeparatorChar);
              String ops[] = new String[] {"-cp" , sb.toString() };This along with disabling security does the trick for me. However I had to use NetX jnlp implementation, since when doing this trick the sun version returns the original urls (like http://internal/webstart/build.jar), whereas NetX returns the path of the downloaded files (e.g. /tmp/build.jar).
    I will accept your suggestion and post to bugs.sun.com.
    Ciao.

  • Trying to follow RMI trail and failing

    I've read through a number of postings here in an effort to try to see a commonality; however, I still can't see what I'm doing wrong.
    I am not a new Java pgm'r, but RMI is brand new to me. I went entirely through the trail:
    http://java.sun.com/docs/books/tutorial/rmi/index.html
    I followed everything as closely as I could and got as far as "Running the Example Programs", and that's where I fell down. I hope all this info does NOT intimidate anyone from reading further, but here goes:
    1. All my 'server' stuff looks like this:
    C:\home\msdwjj\public_html\classes
                                  |
                                  |___client   <dir>
                                  |     |___________Pi.class 
                                  |___compute  <dir>
                                  |     |___________Compute.class
                                  |     |___________Task.class
                                  |___engine   <dir>
                                  |     |___________ComputeEngine_Stub.class
                                  |     |___________ComputeEngine_Skel.class
                                  |___META-INF <dir>
                                  |     |___________MANIFEST.MF
                                  |___compute.jar
                                  |___java.policy
                                  |___startRMI.bat
                                  |___unpack.bat2. All my client stuff is like this:
    C:\MyMoveSubDir\Mysendrecv\Billsdir\RMI\ComputeEngine
                                            |__compute <dir>
                                            |   |__Compute.java
                                            |   |__Compute.class
                                            |   |__Task.java
                                            |   |__Task.class
                                            |__engine  <dir>
                                            |   |__ComputeEngine.java
                                            |   |__ComputeEngine.class
                                            |   |__ComputeEngine_Stub.class
                                            |   |__ComputeEngine_Skel.class
                                            |__client  <dir>
                                            |   |__ComputePi.java
                                            |   |__ComputePi.class
                                            |   |__Pi.java
                                            |   |__Pi.class
                                            |__compute.jar
                                            |__javacjar.bat
                                            |__javacrmi.bat
                                            |__javajarClient.batAll of the above are the result of running the batch files discussed below; and the contents of all of these modules is exactly as posted in the RMI trail I mentioned above. I changed NOT A SINGLE LINE OF CODE, including the package statements.
    The contents of all the server batch files is as follows:
    1. startRMI.bat:
    set CLASSPATH=
    start rmiregistry
    pause
    set CLASSPATH=C:\MyMoveSubDir\Mysendrecv\Billsdir\RMI\ComputeEngine;c:\home\msdwjj\public_html\classes\compute.jar
    pause
    java -D java.rmi.server.codebase=file:/c:\home\msdwjj\public_html\classes/ -D java.rmi.server.hostname=xxxx.xxxx.xxx -D java.security.policy=java.policy engine.ComputeEngine
    pause2. unpack.bat:
    jar xvf compute.jar
    pause3. The contents of the java.policy file is:
    grant {
        permission java.net.SocketPermission "*:1024-65535",
            "connect,accept";
        permission java.io.FilePermission
            "c:\\home\\msdwjj\\public_html\\classes\\-", "read";
    };The contents of all the client batch files is as follows:
    1. javacjar.bat:
    javac compute\*.java
    pause
    jar cvf compute.jar compute\*.class
    pause2. javacrmi.bat:
    set CLASSPATH=C:\MyMoveSubDir\Mysendrecv\Billsdir\RMI\ComputeEngine;c:\home\msdwjj\public_html\classes\compute.jar
    pause
    javac engine\ComputeEngine.java
    pause
    rmic -d . engine.ComputeEngine
    pause
    copy engine\ComputeEngine_*.class c:\home\msdwjj\public_html\classes\engine
    pause3. javacjarClient.bat:
    set CLASSPATH=C:\MyMoveSubDir\Mysendrecv\Billsdir\RMI\ComputeEngine;c:\home\msdwjj\public_html\classes\compute.jar
    pause
    javac client\ComputePi.java
    pause
    javac -d c:\home\msdwjj\public_html\classes client\Pi.java
    pauseThe contents of compute.jar are:
    > Compute.class
    > Task.class
    > Manifest.mf
    I get all through compiling and when I get to actually try to run this, as per the instructions (and via the startRMI.bat file) I get this:
    C:\home\msdwjj\public_html\classes>set CLASSPATH=
    C:\home\msdwjj\public_html\classes>start rmiregistry
    C:\home\msdwjj\public_html\classes>pause
    Press any key to continue . . .
    C:\home\msdwjj\public_html\classes>set CLASSPATH=C:\MyMoveSubDir\Mysendrecv\Bill
    sdir\RMI\ComputeEngine;c:\home\msdwjj\public_html\classes\compute.jar
    C:\home\msdwjj\public_html\classes>pause
    Press any key to continue . . .
    C:\home\msdwjj\public_html\classes>java -D java.rmi.server.codebase=file:/c:\hom
    e\msdwjj\public_html\classes/ -D java.rmi.server.hostname=xxxx.xxxx.xxx -D j
    ava.security.policy=java.policy engine.ComputeEngine
    Exception in thread "main" java.lang.NoClassDefFoundError: java/rmi/server/codeb
    ase=file:/c:\home\msdwjj\public_html\classes/
    C:\home\msdwjj\public_html\classes>pause
    Press any key to continue . . .The C:\jdk1.3.1_04\bin\rmiregistry.exe window does come up.
    So, if you've gotten this far, thank you very much. I hope someone might be able to help me with this. Thanks in advance.
    ~Bill

    boZZi,
    May I ask you another question? ... or for that matter anyone else who can offer another helping hand.
    I changed my host name (stupid mistake, and I did see that one, but I promised the dukes and so there it is). So now my Server side is running and it's at 'ComputeEngine bound'.
    But the last part of this tutorial is extremely confusing to me. It is telling me the following, and you can see it yourself at this link:
    http://java.sun.com/docs/books/tutorial/rmi/running.html
    ... Under the section: 'Start the Client'. There it provides the following instructions:
    "Once the registry and the engine are running, you can start the client,
    specifying The location where the client serves up its classes (the Pi
    class), using the java.rmi.server.codebase property As command line
    arguments the host name of the server--so that the client knows where
    to locate the Compute remote object--and the number of decimal places
    to use in the  calculation The java.security.policy property, used to
    specify the policy file that contains the permissions you intend to
    grant specific code bases First, set the CLASSPATH to see jones's
    client and the JAR file containing the interfaces. Then start the
    client on another host (one named ford, for example) as follows:
    Microsoft Windows:
    set CLASSPATH c:\home\jones\src;c:\home\jones\public_html\classes\compute.jar
    java -Djava.rmi.server.codebase=file:/c:\home\jones\public_html\classes/
         -Djava.security.policy=java.policy
         client.ComputePi zaphod.east.sun.com 20
    UNIX:
    setenv CLASSPATH /home/jones/src:/home/jones/public_html/classes/compute.jar
    java -Djava.rmi.server.codebase=http://ford/~jones/classes/
         -Djava.security.policy=java.policy
            client.ComputePi zaphod.east.sun.com 20"1st off, on my Solaris box, there is no setenv command. 2nd of all, I realize that here the auther is suggesting using an HTTP URL for the Unix OS, and a file URL on the MS OS; but why is the MS FILE URL pointing in the 'codebase' to a directory structure - file:/c:\home\jones\public_html\classes/ - that exist on the server, while on the Unix OS it's pointing to a directory structure on the Client - http://ford/~jones/classes/ ? ... I say that because the instructions are to start the Client from another hostname, and he used as an example 'ford'.
    This particular statement makes no sense to me:
    "The location where the client serves up its classes (the Pi class), using the java.rmi.server.codebase property."
    ... Why would the server.codebase include information on where the client's classes are?
    It's my understanding that the Client programs only - in this case Pi.class and ComputePi.class - exist on the Client. But this tutorial is not particularly clear it seems. What am I missing here ... any ideas? Thanks in advance.
    ~Bill

  • Help with RMI tutorial (and Eclipse)

    Hi!
    I need a little help with RMI tutorial. I have all source files from tutorial downloaded, but I never did anything like this and don't know, how to run it. I somehow did Building a JAR File of Interface Classes from [http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/rmi/compiling.html], but got stuck on simple HTTP server, I didn't understand, what to do.
    Bonus question: is it possible to do those commands from Eclipse? How?
    Thanks a lot!

    It seems that the example provided (in the link) requires a web serverNo it doesn't. It requires an HTTP server.
    tomcat will be a better option which you can useThe Apache HTTP server might be more to the point.
    But If you are new to RMI and need to understand the exact flow of RMI I think this will not be a better exercise to start withI agree. I would get it running without the codebase feature. This isn't as widely used as you might think, and anyway it is a deployment option not something you need to engage with much when developing.
    @OP: ignore the HTTP stuff and the codebase feature and build 3 JAR files:
    (a) the common stuff (remote interface, stubs if any, and any classes referecned by the remote interface)
    (b) the server (the remote object itself and anything server-side it uses)
    (c) the client.
    The common JAR file should be deployed to both the server and the client, and both the other JARs should name it in their Class-Path entry in the manifest.

  • One RMI client and mutliple RMI server implementation

    Hi,
    We are planning to implement a RMI. In the design approach we are planning to have 1 client and mutiple RMI server and each RMI server register to a system. All the RMI server will have the same functionality. The decision to call particualr RMI server is done at runtime based on some parameter. I am not clear on how to implement the same as I am new to RMI technology, so it would be great if you can suggest some good approach for doing the same.
    Thanks,
    Ramreddy

    greetings,
    your client and server are in the same class?
    i.e. server object (interface implementation instance)
    and lookup are within the same execution thread
    i believe this defeats the purpose of RMI
    the objective is to utilize object methods on different machines
    otherwise, you can just use a local method within your server/client mainline (of course, it ceases to become "remote" at that point)
    logistically, there is also the problem of the runtime not being able to resolve the skeleton/proxy components correctly (since it's probably searching for a client stub which doesn't exist...); maybe you could fake it out by compiling a phony client class - again, this won't provide any advantage but it might run
    perhaps if you shared your system/network setup and a bit more about your design objectives someone in this forum could provide some assistance
    good luck,
    D

  • ClassLoader and ClassCastException

    ok, I have a Class named 'Lib' that I want to Load into the virtual machine from a file. I do this by extending ClassLoader and overloading the findClass() method to read the .class file through a FileInputStream.
    Everything is fine until I try casting the 'Lib' object to a 'Lib' type. For example, I can do a
    Object o = loadClass("Lib").newInstance();
    but I cannot do a
    Lib l = (Lib)loadClass("Lib").newInstance();
    This also raises a new question: if you load a class dynamically during the execution of the program, how do you assign it to a new reference type so that you can use it?(i.e how do you make the 'Lib' type if you don't import the class? Incidently, I do import it and it still won't cast the object.)
    I am making sure that the same class loader is loading all instances of the 'Lib' type, namely my(the extended) classloader, but it still won't let me cast. can anyone help??? thx.
    Karl

    Thanks for the comment Vlad. Here is the code I'm using, I verified that it is not being loaded by the bootstrap ClassLoader(default) as I moved it entirely out of the CLASSPATH.
    Class myClass extens ClassLoader{
    public void libInit(){
                            try{
                                            System.out.println("parent class loader: " + ClassLoader.getSystemClassLoader().toString());
                                            ClassLoader c = this.getClass().getClassLoader();
                                            System.out.println("this class loader: " + c.toString());
                                            Lib lib = (Lib)loadClass("Lib").newInstance();
                                            System.out.println("asserting Lib instance. " + lib.toString());
                                    }catch(Exception e){
                                            System.err.println("error2: " + e.toString() + "  " + e.getMessage());
                    public Class findClass(String name){
                            System.out.println("using my findClass()");
                            byte[] b = loadClassData(name);
                            return defineClass("Lib", b, 0, b.length);
                    final Class findLoadedClasses(String name){
                             return null;
                            byte[] b = null;
                            try{
                                    File f = new File("Libs","Lib.class");
                                    FileInputStream fis = new FileInputStream(f);
                                    int i = (int)f.length();
                                    b = new byte;
    System.out.println("boo " + i);
    fis.read(b,0,i);
    fis.close();
    }catch(Exception e){
    // Logger code goes here
    System.err.println("error1: " + e.getMessage());
    return b;
    The above fails on the cast from the newInstance() method. In the above code is the first place in the program where I even reference a 'Lib' type.
    Also, instead of using a 'Lib' type, how could I read a class file into a reference type? Is this what java.lang.ref is for? thanks.
    Karl

Maybe you are looking for