gpt4 book ai didi

Java RMI,找不到 stub 类,java.rmi.ServerException : RemoteException occurred in server thread;

转载 作者:行者123 更新时间:2023-12-01 17:27:07 25 4
gpt4 key购买 nike

我正在尝试运行我的 rmi 程序。然而它似乎找不到我的 stub 类。我执行命令“start rmiregistry”,该命令成功启动。然后做完之后:

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

我已经在不同的计算机上厌倦了这个问题,但我没有遇到这个问题,它似乎只发生在我的笔记本电脑上,我的环境变量有问题吗?我检查了我的环境变量与我厌倦运行它的另一台电脑相同。

这是我的类(class)的代码:

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);

}
}
}

感谢您的帮助。

最佳答案

确保从有权访问您的类的目录(bin/根文件夹,而不是包文件夹)启动rmiregistry

关于Java RMI,找不到 stub 类,java.rmi.ServerException : RemoteException occurred in server thread;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com