public class Startup{
public static void main(String[] args)throws Exception{
PKGenerator generator=new PKGenerator();
Context ctx=new InitialContext(System.getProperties());//这句有问题,要配置你的服务器对应的Properties
ctx.rebind("PKGenerator",generator);
System.out.println("PKGenerator bound to JNDI tree.");
synchronized(generator){
generator.wait();
}
}
}
由于你的JNDI的上下文没有创建起来,所以后面的工作都不能进行了
public static void main(String[] args)throws Exception{
PKGenerator generator=new PKGenerator();
Context ctx=new InitialContext(System.getProperties());//这句有问题,要配置你的服务器对应的Properties
ctx.rebind("PKGenerator",generator);
System.out.println("PKGenerator bound to JNDI tree.");
synchronized(generator){
generator.wait();
}
}
}
由于你的JNDI的上下文没有创建起来,所以后面的工作都不能进行了
解决方案 »
- 哪些著名的系统是JAVA做的,到底是选择JAVA好还是选择.NET好。
- 关于java反射的安全问题
- 网站整站样式
- MySQL连接问题,知道了帮下忙,谢谢。
- 400万条数据存到本地,你会怎么存?
- hibernate的联合主键的问题?
- 请教一个有难度的好题。高手来帮忙看看
- 在jb调试成功了,发布在websphere成功了但是htm可以看,jsp不可以运行?为什么??
- weblogic8 出现如下错误,请问是什么回事?????
- 闷闷闷,在JBuilder中,为什么我一运行汉字输入法(如:全拼、双拼等),JBuilder程序就会死。
- java调用标准的linux C
- XML 中有这个<!DOCTYPE PLAY SYSTEM "plays.dtd">,急
还需要高手详细指点一下。
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
四个文件:[代码在后]
Product.java
ProductImpl.java
ProductServer.java
ProductClient.java
步骤:
1.正常编译四个文件。
2.运行rmic -v1.2 *** 生成代理文件***_stub.class。该文件必须放置在客户端。
3.运行rmiregistry。
4.启动服务器。
5.运行客户端。
//***************************
//Product.java
import java.rmi.*;
public interface Product extends Remote
{
String getDescription() throws RemoteException;
}
//********************************
//ProductImpl.java
import java.rmi.*;
import java.rmi.server.*;
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;
}
//*********************************
//ProductServer.java
import java.rmi.*;
import java.rmi.server.*;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..."); Naming.rebind("toaster", p1);
Naming.rebind("microwave", p2); System.out.println("Waiting for invocations from clients...");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
//******************************8
ProductClient.java
import java.rmi.*;
import java.rmi.server.*;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
{
Product c1 = (Product)Naming.lookup(url + "toaster");
Product c2 = (Product)Naming.lookup(url + "microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
你说的启动服务器时说的什么服务器呀,我只有j2sdkee1.3,这个可以吗,该怎么样配置呀,我刚学习j2ee,不是太懂,请多多帮忙
orbd -ORBInitialPort 1050
Properties prop = new Properties();
Properties contextprop = new Properties(); contextprop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
contextprop.put(Context.PROVIDER_URL,"iiop://yourip:1050"); Context initialNamingContext = new InitialContext(contextprop);
initialNamingContext.rebind("",);
注意用rmic -iiop generator
才是iiop协议哦。
",generator);考,太匆忙!
客户端的初始化也一样。