/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Java RMI Problem - Java in 21 days related
Fra : Dave Graham


Dato : 08-09-01 14:55

If I have sent this to the wrong newsgroup, I apologise for cluttering
up the group.

Hi

I'm trying to teach myself Java, using the "Teach Yourself Java in 21
Days" book. I hope that someone might be able to help me with a
problem I'm having with RMI in chapter 18, if someone could help I'd
be very grateful. I have not ever written a client-server application
before, so it could be that my lack of understanding of what the
example is meant to show is getting in the way. I'm using a PC running
on Windows Millenium.

I'll describe the procedure as it is outlined in the book, what I am
doing and the problems I am encountering. There are 3 java files, part
of a package "com.prefect.pi". I have created a directory structure
"c:\abovecom\com\prefect\pi" and placed the directory "c:\abovecom" on
my CLASSPATH. The 3 java files are:

File 1, PiRemote.java:
package com.prefect.pi;

import java.rmi.*;

interface PiRemote extends Remote {
   double getPi() throws RemoteException;
}

File 2, Pi.java:
package com.prefect.pi;

import java.net.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class Pi extends UnicastRemoteObject implements PiRemote {

   public double getPi() throws RemoteException {
      return Math.PI;
   }

   public Pi() throws RemoteException {
   }

   public static void main(String[] arguments) {
      System.setSecurityManager(new   RMISecurityManager());
      try {
         Pi p = new Pi();
         System.out.println("Before bind");
         Naming.bind("//Default:1010/Pi", p);
      } catch (Exception e) {
         System.out.println("Error -- " + e.toString());
         e.printStackTrace();
      }
   }
}

File3, OutputPi.java
package com.prefect.pi;

import java.rmi.*;
import java.rmi.registry.*;

public class OutputPi {
   public static void main(String[] arguments) {
      System.setSecurityManager(new RMISecurityManager());
      try {
         PiRemote pr = (PiRemote)Naming.lookup("//Default:1010/Pi");
         for (int i = 0; i < 10; i++)
            System.out.println("Pi = " + pr.getPi());
      } catch (Exception e) {
         System.out.println("Error -- " + e.toString());
         e.printStackTrace();
      }
   }
}   

I have saved these files and compiled them in the directory
c:\abovecom\com\prefect\pi, so I have 3 java files and 3 class files.
The first thing the book states is that the text "Default" should be
replaced with your computer name, gotten from Identification tag in
the Network setting on the Control Panel, my computer name is
"Computer", so before compiling Pi.java and OutputPi.java I changed
the text "//Default:1010/Pi" to be "//Computer:1010/Pi".

The book then instructs me to go to the folder that contains the file
Pi.class (c:\abovecom\com\prefect\pi in my case) and run the following
command from the command line "rmic com.prefect.pi.Pi". This command
is supposed to create two class files "Pi_Stub.class" and
"Pi_Skel.class". The command does indeed do this but it creates them
in a replicated directory structure under the current one, so I end up
with a directory "c:\abovecom\com\prefect\pi\com\prefect\pi" and it is
in this directory that the two new class files are located. At later
stages in the process, I have alternately tried to make things work
with the files left where they are and also moved back up the
directory structure i.e. to where my 3 java files and 3 class files
reside.

Next I am instructed to run the rmiregistry program but first ensure
that the Pi_Stub.class file and Pi_Skel.class file are not on my
CLASSPATH. To do this I remove the directory "C:\abovecom" from my
CLASSPATH variable. I then run the command "start rmiregistry 1010"
which seems to open another MSDOS session, although no prompt or
anything else is present.

I am then instructed to start the Pi program, so I return to my
original MSDOS session and type the command
"java -Djava.rmi.server.codebase=c:\abovecome\ com.prefect.pi.Pi"
and I get Security Access Control Exceptions, in the book it says that
the correct command would be
"java -Djava.rmi.server.codebase=http://www.naviseek.com/java21/java/
com.prefect.pi.Pi"
if the class files were stored at
"http://www.naviseek.com/java21/java".

I've tried different variations of directory structures, different
versions of the last command, changing the name "Computer" back to
"Default" and one or two other things all to no avail. I cannot get
any further.

Reading the book what is meant to happen subsequent to this point is
that I run "java com.prefect.po.OutputPi" and I will see the value of
Pi being displayed 10 times, I assume in the rmiregistry window?

Anyway, I have a number of questions, if anyone can help?

(1) Am I doing something wrong with the "codebase" command?
(2) The author repeatedly states "switch folders" to where a
particular class file is, but I have my 3 class files in the same
folder, is this a mistake?
(3) Does anyone who has done this book know what the correct result of
this exercise is i.e. do the value for Pi appear in the rmiregistry
window?

Again, I would be extrememly thankful if anyone could get me past this
problem.

Regards
Dave Graham

 
 
Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste