rmiプログラムを実行しようとしています。ただし、スタブクラスが見つからないようです。正常に起動するコマンド「startrmiregistry」を実行します。その後:
java -classpath . -Djava.security.policy=AllSecurity.policy RMIAuctionManagerImpl
次のエラーが発生します:
Failed to register object java.rmi.ServerException: RemoteException occurred in
server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: RMIAuctionManagerImpl_Stub
java.rmi.ServerException: RemoteException occurred in server thread; nested exce
ption is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: RMIAuctionManagerImpl_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
53)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
t.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:603)
at java.lang.Thread.run(Thread.java:722)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at RMIAuctionManagerImpl.main(RMIAuctionManagerImpl.java:133)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
java.lang.ClassNotFoundException: RMIAuctionManagerImpl_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
53)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
t.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: RMIAuctionManagerImpl_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:453)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:184)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.jav
a:216)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:159
3)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
... 13 more
私はこれを別のコンピューターで疲れさせましたが、この問題は発生しません。ラップトップで発生しているようですが、環境変数に問題がありますか?これを実行するのに疲れた他のPCと同じ環境変数を確認しました。
これが私のクラスのコードです:
import java.io.Serializable;
import java.util.ArrayList;
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
public class RMIAuctionManagerImpl extends UnicastRemoteObject implements RMIAuctionManager, Serializable {
protected ArrayList<RMIAuctionItem> itemList ;
protected ArrayList<RMIBidder> bidderList;
public RMIAuctionManagerImpl() throws RemoteException
{
itemList= new ArrayList<RMIAuctionItem>();
bidderList=new ArrayList<RMIBidder>();
}
public ArrayList<RMIBidder> getBidders() throws RemoteException
{
return bidderList;
}
public ArrayList<RMIAuctionItem> getItems() throws RemoteException
{
return itemList;
}
public RMIAuctionItem findItem(String itemName) throws RemoteException
{
for(int i =0; i<itemList.size();i++)
{
if(itemList.get(i).getName()==itemName)
{
return itemList.get(i);
}
}
return null;
}
public void add(RMIBidder aBidder) throws RemoteException
{
bidderList.add(aBidder);
}
public void sendMessageToServer(RMIAuctionItem aItem, RMIBidder aBidder, double theMessage) throws RemoteException
{
Connection conn =null;
PreparedStatement prestmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
System.out.println("Driver Not Found");
e.printStackTrace();
}
try {
conn = DriverManager.getConnection("jdbc:odbc:RMIAuctionHouseDB");
} catch (SQLException e) {
System.out.println("Connection Not Found");
e.printStackTrace();
}
try {
String insertSQL = "Insert into RMIAuctionHouse (ItemName, ClientName, BidAmount) VALUES (?,?,?)";
prestmt = conn.prepareStatement(insertSQL);
prestmt.setString(1, aItem.getName());
prestmt.setString(2, aBidder.getName());
prestmt.setDouble(3, theMessage);
} catch (SQLException e1) {
System.out.println("Statement Not Found");
e1.printStackTrace();
}
try {
prestmt.executeUpdate();
} catch (SQLException e) {
System.out.println("Sql Query Not Found");
e.printStackTrace();
}
try {
prestmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
aItem.makeBid(aBidder, theMessage);
}
public void joinBidding(RMIBidder aBidder,RMIAuctionItem aItem) throws RemoteException
{
System.out.println("Bound Client: "+ aBidder.getName()+ " to "+ aItem.getName());
aItem.joinBidding(aBidder);
}
public void setItems() throws RemoteException
{
RMIAuctionItem aItem=new RMIAuctionItemImpl();
aItem.setName("Ps3");
aItem.setPrice(200);
RMIAuctionItem aItem2= new RMIAuctionItemImpl();
aItem2.setName("Macbook");
aItem2.setPrice(500);
RMIAuctionItem aItem3=new RMIAuctionItemImpl();
aItem3.setName("HTC Desire HD");
aItem3.setPrice(100);
itemList.add(aItem);
itemList.add(aItem2);
itemList.add(aItem3);
}
public void deleteItems() throws RemoteException
{
for(int i=0; i<itemList.size();i++)
{
itemList.remove(itemList.get(i));
}
}
public static void main (String[] args)
{
try{
RMIAuctionManager myRMIAuctionManager=new RMIAuctionManagerImpl();
Naming.rebind("RMIAuctionServer", myRMIAuctionManager);
//myRMIAuctionManager.deleteItems();
//myRMIAuctionManager.setItems();
System.out.println("Remote object bound to registry");
}
catch( Exception e){
System.out.println("Failed to register object " + e);
e.printStackTrace();
System.exit(1);
}
}
}
ヘルプをありがとう。