Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Работа с сетью > клиент-серверное приложение с использованием RMI


Автор: SolarCell 1.7.2008, 21:05
Здравствуйте... Пытаюсь создать простенькое клиент-серверное приложение. Нашла примеры, пробую.
Вот код реализации интерфейса сервера:

Код

package serverclient;

//realization of remote  Billingservice interface

import java.rmi.*;
import java.util.*;
import java.rmi.server.*;
import serverclient.NotExistsCardOperation;

public class BillingServiceImpl extends UnicastRemoteObject implements BillingService{
private Hashtable hash;

public BillingServiceImpl() throws RemoteException{
super();
hash=new Hashtable();
}

public void addNewCard(String personName,String card) throws RemoteException{
hash.put(card,new Double(0.0));
}

public void addMoney(String card,double money) throws RemoteException{
Double d=(Double)hash.get(card);
if(d!=null) hash.put(card,new Double(d.doubleValue()+money));
else throw new NotExistsCardOperation();
}

public void subMoney(String card,double money) throws RemoteException{
Double d=(Double)hash.get(card);
if(d!=null) hash.put(card,new Double(d.doubleValue()-money));
else throw new NotExistsCardOperation();
}

public double getCardBalance(String card) throws RemoteException{
Double d=(Double)hash.get(card);
if(d!=null) return d.doubleValue();
else throw new NotExistsCardOperation();
}

//start remote service
public static void main(String args[]) throws Exception{
System.out.println("Initializing BillingService.......");
BillingService service=new BillingServiceImpl();
//the name of remote object
String serviceName="rmi://localhost/BillingService";
//registration of the remote object in the rmiregistry
Naming.rebind(serviceName,service);
}
}


С помощью rmic создаю заглушку, с помощью rmiregistry запускаю реестр, после запускаю сервер, и  получаю кучу исключений. 

Вот трассировка:

c:\Java>java serverclient.BillingServiceImpl
Initializing BillingService.......
Exception in thread "main" java.rmi.ServerException: Server RemoteException; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: serverclient.BillingServiceImpl_Stub
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
        at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at java.rmi.Naming.rebind(Unknown Source)
        at serverclient.BillingServiceImpl.main(BillingServiceImpl.java:47)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: serverclient.BillingServiceImpl_Stub
Caused by: java.lang.ClassNotFoundException: serverclient.BillingServiceImpl_Stub

Помогите, пожалуйста, разобраться, отчего возникает это исключение...package serverclient;

Автор: Platon 1.7.2008, 22:40
Я давно забыл как там реализована работа с RMI. Но по приведенному стек-трейс могу сделать вывод, что 

Цитата(SolarCell @  1.7.2008,  22:05 Найти цитируемый пост)
java.lang.ClassNotFoundException: serverclient.BillingServiceImpl_Stub        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)


Получена ошибка от сервера. Серверное приложение ругается на то, что ему не достает в classpath класса serverclient.BillingServiceImpl_Stub Проверь, всё ли правильно там у тебя?

Автор: SolarCell 2.7.2008, 09:28
Классы у меня все находятся в C:\Java\bin, в CLASSPATH этот путь прописан, если бы нет, класс сервера вообще не запускался бы, но он запускается, а потом когда доходит до
Код

BillingService service=new BillingServiceImpl();
//the name of remote object
String serviceName="rmi://localhost/BillingService";
//registration of the remote object in the rmiregistry
Naming.rebind(serviceName,service);

выдаёт эти exceptions, хотя класс заглушки создан, и хранится он в C:\Java\bin\serverclient\ , как и все остальные классы. Если остальные выполняются из этой директории, то и заглушка должна быть видна? Или нет?  

Автор: LSD 2.7.2008, 10:08
У тебя не может найти заглушку: java.lang.ClassNotFoundException: serverclient.BillingServiceImpl_Stub, проверь что ты ее скомпилировал и положил в classpath.

Автор: SolarCell 2.7.2008, 10:32
Вопрос: как нужно компилировать заглушку? 
Она создана - 
BillingServiceImpl_Stub.class


нужно что-то ещё?

Добавлено через 8 минут и 23 секунды
Вот ещё, смотрю класс заглушки, и вижу там - 
stub class initialization failed
 smile 

Автор: SolarCell 2.7.2008, 13:31
Спасибо всем, всё работает))

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)