java.rmi.UnmarshalException:errorunmarshalling return; java.lang.ClassNotFoundException的解决方法

1)problem

出现 java.rmi.UnmarshalException:   error   unmarshalling   return;   nested   exception   is:   

java.lang.ClassNotFoundException 异常的原因是,在命令行执行 rmiregistry,并没有指定好 绑定时查找的类文件的路径。

2)solution

这里写图片描述

以上图片是我的一个荔枝,我的需要绑定的类所属类名如下:

package com.corejava.chapter11.activation.server;

import java.rmi.*;

/**
   The remote interface for a simple warehouse.
   @version 1.0 2007-10-09
   @author Cay Horstmann
*/
// 远程对象的接口必须扩展Remote接口
public interface Warehouse extends Remote
{  
   double getPrice(String description) throws RemoteException;
}


我们通过如下语句将该类注册到注册表( Naming.rebind("rmi://localhost:1099/central_warehouse", centralWarehouse);
)时,1099是 rmiregistry的启动默认端口,发送该绑定请求后,registry 就会去查找要绑定的 centralWarehouse 所属的类名,也即是 com.corejava.chapter11.activation.server.Warehouse。


package com.corejava.chapter11.activation.server;

import java.io.*;
import java.rmi.*;
import java.rmi.activation.*;
import java.util.*;

import javax.naming.*;

public class WarehouseActivator
{
	public static void main(String[] args) throws RemoteException,
			NamingException, ActivationException, IOException,
			AlreadyBoundException
	{
		System.out.println("Constructing activation descriptors...");
		System.setProperty("java.security.policy",
				"com/corejava/chapter11/activation/server/server.policy");
		System.setSecurityManager(new SecurityManager());

		// 如何构建激活程序
		Properties props = new Properties();
		// use the server.policy file in the current directory
		props.put("java.security.policy", new File(
				"com/corejava/chapter11/activation/server/server.policy")
				.getCanonicalPath());
		// step1)需要定义一个激活组
		// step2) 然后如下构造一个激活组描述符:
		ActivationGroupDesc group = new ActivationGroupDesc(props, null);
		// step3)创建一个组ID
		ActivationGroupID id = ActivationGroup.getSystem().registerGroup(group);

		Map<String, Double> prices = new HashMap<>();
		prices.put("Blackwell Toaster", 24.95);
		prices.put("ZapXpress Microwave Oven", 49.95);

		MarshalledObject<Map<String, Double>> param = new MarshalledObject<Map<String, Double>>(
				prices);

		String codebase = "http://localhost:8080/";

		// step4) 构造一个激活描述符了。对于需要构造的每一个对象,都应该包括以下内容(contents):
		// 激活组ID + 类的名字 + URL字符串 + 编组后的构造信息
		// LocateRegistry.createRegistry(1099);
		ActivationDesc desc = new ActivationDesc(id,
				"com.corejava.chapter11.activation.server.WarehouseImpl",
				codebase, param);
		Warehouse centralWarehouse = (Warehouse) Activatable.register(desc);

		Naming.rebind("rmi://localhost:1099/central_warehouse", centralWarehouse);
		System.out.println("Exiting...");
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值