来晚了,我在java.sun.com的forum上问过类似问题,下面是一则回复:Context.PROVIDER_URL is required only when you have have to connect from remote location.If your code using JNDI is on same machine, that has the application server, then you donot need to specify PROVIDER_URL or INITIAL_CONTEXT_FACTORY. You can get the InitialContext using the default constructor as- Context ctx = new InitialContext();else you need to specify both of these. 帖子的地址: http://forum.java.sun.com/thread.jsp?thread=198336&forum=51&message=656557另外,那个Context.INITIAL_CONTEXT_FACTORY和Context.INITIAL_CONTEXT_FACTORY要视application server而定的,比如我用的是JBoss3.0.2,我的jndi代码如下: Properties env = System.getProperties(); env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); env.put("java.naming.provider.url","192.168.0.168:1099"); env.put("java.naming.factory.url.pkgs","org.jboss.naming.:org.jnp.interfaces"); InitialContext context = new InitialContext(env); Object obj = context.lookup("UserRemote"); 你的是什么?realplay(代码录入员) 的回复我认为是详细和正确的,请仔细参考 btw,你最好贴出exception stacktrace让大家看看
谢谢各位捧场,我用的就是各位所提到的初始化上下文的方法,客户机的JRE中也包含了初始化上下文所需的类库,可是报的错是: java.lang.NullPointerException: at weblogic.i18tools.i10LookUp.loadProps(.....) ................................ 这到底是为什么?
to chenyuan_tongji(codeguru): 我们遇到的问题不一样,我最初遇到的异常是说客户机器上没有WLInitialContext类,现在这个异常已经解决了,反倒出了个空指针
http://www-900.ibm.com/websphere/techjournal/0110_wosnick/index_eng.shtml
我的客户端程序其实是想通过服务器上的消息驱动bena穿点数据,可是就是没法初始上下文
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,url);
//连接服务器的代码,针对不同的中间件,不同
Context CalDueValueInterface=new InitialContext(p);
Object obj=CalDueValueInterface.lookup(lus);
CalDueHome home=(CalDueHome)PortableRemoteObject.narrow(obj,CalDueHome.class);
CalDue se = (CalDue)home.create();webshpere:
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
private Context getInitialContext() throws Exception
{
String url = "t3://bigbear:7001"; //bigbear:安装weblogic服务器
String user = null;
String password = null;
Properties properties = null;
try
{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null)
{
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e)
{
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
ip写你的weblogic服务器难道不行吗?
这种方法好象只能用于客户端程序部署在服务器上,由客户机器调用的情况。
我现在是想在客户机器上运行一个applocation(application存在客户机器上),这时我认为需要对客户机器上的jre进行特殊的处理,各位觉得呢?
weblogic.jndi.WLInitialContextFactory
客户机根本没有提供上下文环境的包
.所以你把weblogic.jar(可能还需其它包)都
弄到客户机上,一定可以..然后再慢慢精简.一定行的---------------------->
有这个类,我已经把它加入到rt.jar中了
我已经这样做了,现在报weblogic.i18tools.中一个类中的loadProps()方法抛出了空指针错误(具体类名我忘记了)
光设置Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL好像不行因为查到的是一个引用所以必然要对引用的实现不如rmi和iiop等所以好想要设置别的属性。
十分关注。
患难兄弟,我也是为了调用服务器上的一个消息驱动bean,你后来是怎么解决的?
肯定是缺少某些包或配置不对,
APPLICATION和WEBLOGIC是不同的独立进程跑的.
可以共享的就只是那些包,
所以,在开发环境上能跑的话,只要CLASSPATH包含了足够的类库,只要把这些类库移到另一台机上,肯定是可以跑的.
因此根本上与你的开发环境的WEBLOGIC配置无关
只可能是某些包缺少或是应用程序的问题
本来WEBLOGIC就是在JDK131上跑起来的.怎么可能你把APPLICATION独立离开发环境就跑不了.
那是不可能的.
当应用服务器接到消息就用messagedriverbean来出来消息
import javax.rmi.*;
import javax.naming.*;
import java.util.*;//Äã×Ô¼ºµÄEJB½Ó¿Ú (TimeFunctions)
import sbtutorial.*;public class EjbClient{
String url = "t3://192.168.0.67:9001";
String user = null;
String password = null;
Properties h = new Properties(); public Context getInitialContext(String url,String user,String password) throws NamingException {
try{
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL,url);
//h.put(Context.SECURITY_PRINCIPAL,user);
//h.put(Context.SECURITY_CREDENTIALS,password);
return new InitialContext(h);
}catch(NamingException ne)
{
throw ne;
}
}
public void EjbClient(){
}
public static void main(String[] args) {
EjbClient ejbClient = new EjbClient();
ejbClient.start();
} private void start(){
try{
Context initial = getInitialContext(url,user,password);
Object objref = initial.lookup("TimeFunctions");
TimeFunctionsHome tfHome = (TimeFunctionsHome)PortableRemoteObject.narrow(objref,TimeFunctionsHome.class);
TimeFunctions tfEjb = tfHome.create();
System.out.println(tfEjb.getTime());
}catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}就这样就可以了,我刚测试完,不信我把EJB和上面的源码发给你
在客户端调用EJB有两个条件1.必须有JDK(JRE)
2.必需要第三方(这里是WEBLOGIC)提供的JNDI上下文环境(weblogic.jndi.WLInitialContextFactory)
3.javax.naming
4.java.rmi,javax.rmi是捕获错误的类包如果你用jms,则还需要包含
javax.jms.*;真是不知你是怎么试的,只要有上面的东西,就一定能行...快把1000分给我吧.............
You can get the InitialContext using the default constructor as-
Context ctx = new InitialContext();else you need to specify both of these.
帖子的地址:
http://forum.java.sun.com/thread.jsp?thread=198336&forum=51&message=656557另外,那个Context.INITIAL_CONTEXT_FACTORY和Context.INITIAL_CONTEXT_FACTORY要视application server而定的,比如我用的是JBoss3.0.2,我的jndi代码如下:
Properties env = System.getProperties();
env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url","192.168.0.168:1099");
env.put("java.naming.factory.url.pkgs","org.jboss.naming.:org.jnp.interfaces");
InitialContext context = new InitialContext(env);
Object obj = context.lookup("UserRemote");
你的是什么?realplay(代码录入员) 的回复我认为是详细和正确的,请仔细参考
btw,你最好贴出exception stacktrace让大家看看
java.lang.NullPointerException:
at weblogic.i18tools.i10LookUp.loadProps(.....)
................................
这到底是为什么?
我们遇到的问题不一样,我最初遇到的异常是说客户机器上没有WLInitialContext类,现在这个异常已经解决了,反倒出了个空指针
> at weblogic.i18tools.i10LookUp.loadProps(.....)
>................................
>这到底是为什么?to liukuncn(咖啡泡JAVA):weblogic我不是很熟,但是从你的exception和我的常识分析:你注意到i18tools了没有,这个就是internationalization。这个exception我理解为你的weblogic试图加载i18n资源,比如最常见的字符串资源,但是没有找到。你的ejb或者web applicaiton等等,有没有哪里用到了多语言支持?抱歉,由于你的exception stack strace给的不全,加上我能力有限,目前只能给你这个参考。
21cnfox
21cnfox
set CLASSPATH 試試看,因該可以解決的
Thanks a lot!
结贴。