ClassNotFoundException on Core Java 2 RMI example

Discussion in 'Java' started by ZelluX, Jun 2, 2008.

  1. ZelluX

    ZelluX Guest

    Hi all,
    I'm trying out some sample code on Core Java 2 Chapter 5 - Distributed
    Objects, but even though the code is identical to that on the book, it
    says

    javax.naming.CommunicationException [Root exception is
    java.rmi.ServerException: RemoteException occurred in server thread;
    nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments;
    nested exception is:
    java.lang.ClassNotFoundException: Product]
    ....

    Code snippets(comments and imports removed):

    public interface Product extends Remote {
    String getDescription() throws RemoteException;
    }

    public class ProductClient {
    public static void main(String[] args) {
    System.setProperty("java.security.policy", "client.policy");
    System.setSecurityManager(new RMISecurityManager());
    String url = "rmi://localhost/";
    try {
    Context namingContext = new InitialContext();
    Product c1 = (Product) namingContext.lookup(url + "toaster");
    Product c2 = (Product) namingContext.lookup(url +
    "microwave");

    System.out.println(c1.getDescription());
    System.out.println(c2.getDescription());
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    public class ProductImpl extends UnicastRemoteObject implements
    Product {
    public ProductImpl(String n) throws RemoteException {
    name = n;
    }

    public String getDescription() throws RemoteException {
    return "I am a " + name + ". Buy me!";
    }

    private String name;
    }

    public class ProductServer {
    public static void main(String args[]) {
    try {
    System.out.println("Constructing server implementations...");

    ProductImpl p1 = new ProductImpl("Blackwell Toaster");
    ProductImpl p2 = new ProductImpl("ZapXpress Microwave Oven");

    System.out.println("Binding server implementations to
    registry...");
    Context namingContext = new InitialContext();
    namingContext.bind("rmi:toaster", p1);
    namingContext.bind("rmi:microwave", p2);
    System.out.println("Waiting for invocations from
    clients...");
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    All the files are under /home/abc/Product, and I run the program
    following these steps:
    cd /home/abc/Product
    rmiregistry &
    java ProductServer

    then the error occurs

    Java version: 1.6.0 (so there's no need to run rmic according to the
    book)

    How to solve the problem? Many thanks
     
    ZelluX, Jun 2, 2008
    #1
    1. Advertising

  2. ZelluX

    ZelluX Guest

    On Jun 2, 7:33 pm, Lew <> wrote:
    > ZelluX wrote:
    > > Hi all,
    > > I'm trying out some sample code on Core Java 2 Chapter 5 - Distributed
    > > Objects, but even though the code is identical to that on the book, it
    > > says

    >
    > > javax.naming.CommunicationException [Root exception is
    > > java.rmi.ServerException: RemoteException occurred in server thread;
    > > nested exception is:
    > > java.rmi.UnmarshalException: error unmarshalling arguments;
    > > nested exception is:
    > > java.lang.ClassNotFoundException: Product]
    > > ...

    >
    > > Code snippets(comments and imports removed):

    >
    > Were there any 'package' statements?
    >
    > > All the files are under /home/abc/Product, and I run the program
    > > following these steps:
    > > cd /home/abc/Product
    > > rmiregistry &
    > > java ProductServer

    >
    > > then the error occurs

    >
    > You have a deployment problem on the server, namely that the Product.class
    > file is not accessible to it.
    >
    > --
    > Lew


    No packages decleared, and all files are accessible
     
    ZelluX, Jun 4, 2008
    #2
    1. Advertising

  3. ZelluX

    ZelluX Guest

    On Jun 2, 7:33 pm, Lew <> wrote:
    > ZelluX wrote:
    > > Hi all,
    > > I'm trying out some sample code on Core Java 2 Chapter 5 - Distributed
    > > Objects, but even though the code is identical to that on the book, it
    > > says

    >
    > > javax.naming.CommunicationException [Root exception is
    > > java.rmi.ServerException: RemoteException occurred in server thread;
    > > nested exception is:
    > > java.rmi.UnmarshalException: error unmarshalling arguments;
    > > nested exception is:
    > > java.lang.ClassNotFoundException: Product]
    > > ...

    >
    > > Code snippets(comments and imports removed):

    >
    > Were there any 'package' statements?
    >
    > > All the files are under /home/abc/Product, and I run the program
    > > following these steps:
    > > cd /home/abc/Product
    > > rmiregistry &
    > > java ProductServer

    >
    > > then the error occurs

    >
    > You have a deployment problem on the server, namely that the Product.class
    > file is not accessible to it.
    >
    > --
    > Lew


    No package statements
    And the file permissions have been set to -rw-r--r--
     
    ZelluX, Jun 10, 2008
    #3
  4. ZelluX

    ZelluX Guest

    On Jun 10, 6:59 pm, Lew <> wrote:
    > ZelluX wrote:
    > > And the file permissions have been set to -rw-r--r--

    >
    > For what file, exactly?
    >
    > --
    > Lew


    I successfully run the server with parameter -
    Djava.rmi.server.codebase=file:classDir/
    But strangely on windows I can start the server without the parameter.

    Thanks a lot~
     
    ZelluX, Jun 10, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zhao
    Replies:
    3
    Views:
    3,280
    Roedy Green
    Jul 16, 2003
  2. John C. Bollinger
    Replies:
    0
    Views:
    476
    John C. Bollinger
    Aug 18, 2003
  3. Jan Schulze
    Replies:
    1
    Views:
    580
    Esmond Pitt
    Mar 26, 2005
  4. gmercer
    Replies:
    2
    Views:
    396
    HalcyonWild
    Apr 1, 2005
  5. cdvr
    Replies:
    9
    Views:
    11,073
    Esmond Pitt
    Mar 27, 2007
Loading...

Share This Page