程序清单:
import javax.naming.*;
import java.util.Properties;
public class JNDITest{
public static void main(String ar[]){
Context ctx=null;
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
try{ ctx=new InitialContext(p);
String test="JNDI Test example";
ctx.bind("name",test);
String s=(String)ctx.lookup("name");
System.out.println(s);
String str="welcome to you";
ctx.rebind("name",str);
s=(String)ctx.lookup("name");
System.out.println(s);
}catch(NamingException e){System.out.println(e.toString());}
}
}运行后显示错误:
javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.
WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web
logic.jndi.WLInitialContextFactory]
服务器是weblogic,然后在记事本里写的程序。把weblogic.jar放到jre\lib\ext下面后出现错误:
Exception in thread "main" java.lang.AssertionError: An error occurred while re
rieving the network addresses for this machine. The most likely cause is an err
r in the network configuration of this machine.
        at weblogic.server.channels.AddressUtils$AddressMaker.getAllAddresses(A
dressUtils.java:63)
        at weblogic.server.channels.AddressUtils$AddressMaker.<clinit>(AddressU
ils.java:46)
        at weblogic.server.channels.AddressUtils.getLocalHost(AddressUtils.java
84)
        at weblogic.server.channels.ServerChannelImpl.update(ServerChannelImpl.
ava:533)
        at weblogic.server.channels.ServerChannelImpl.<init>(ServerChannelImpl.
ava:469)
        at weblogic.server.channels.ServerChannelImpl.<init>(ServerChannelImpl.
ava:426)
        at weblogic.server.channels.ServerChannelImpl.createDefaultServerChanne
(ServerChannelImpl.java:702)
        at weblogic.servlet.internal.ProtocolHandlerHTTP$ChannelInitializer.<cl
nit>(ProtocolHandlerHTTP.java:31)
        at weblogic.servlet.internal.ProtocolHandlerHTTP.getDefaultServerChanne
(ProtocolHandlerHTTP.java:36)
        at weblogic.protocol.ServerChannelManager$SingletonMaker$1.getOutboundS
rverChannel(ServerChannelManager.java:339)
        at weblogic.protocol.ServerChannelManager.findOutboundServerChannel(Ser
erChannelManager.java:243)
        at weblogic.rjvm.RJVMManager.findOrCreateRemoteInternal(RJVMManager.jav
:238)
        at weblogic.rjvm.RJVMManager.findOrCreate(RJVMManager.java:202)
        at weblogic.rjvm.RJVMFinder.findOrCreateRemoteServer(RJVMFinder.java:22
)
        at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:189)
        at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:154)
        at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLIn
tialContextFactoryDelegate.java:349)
        at weblogic.jndi.Environment.getContext(Environment.java:307)
        at weblogic.jndi.Environment.getContext(Environment.java:277)
        at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialCon
extFactory.java:117)
        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
        at javax.naming.InitialContext.init(Unknown Source)
        at javax.naming.InitialContext.<init>(Unknown Source)
        at JNDITest.main(JNDITest.java:11)
Caused by: java.net.UnknownHostException: ??0??2
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
        at java.net.InetAddress.getAddressFromNameService(Unknown Source)
        at java.net.InetAddress.getAllByName0(Unknown Source)
        at java.net.InetAddress.getAllByName(Unknown Source)
        at java.net.InetAddress.getAllByName(Unknown Source)
        at weblogic.server.channels.AddressUtils$AddressMaker.getAllAddresses(A
dressUtils.java:51)
        ... 24 more
请大侠不吝赐教啊!

解决方案 »

  1.   

    主要是javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi. 
    WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web 
    logic.jndi.WLInitialContextFactory] 
      

  2.   

    javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi. 
    WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web 
    logic.jndi.WLInitialContextFactory] 
    无法初始化类(主要是因为找不到类weblogic.jndi.WLInitialContextFactory)
    Exception in thread "main" java.lang.AssertionError: An error occurred while re 
    rieving the network addresses for this machine. The most likely cause is an err 
    r in the network configuration of this machine.
    在重获本机网络地址时出错,可能是本机网络地址配置出错 
      

  3.   

    我把weblogic.jar包添加到环境变量后就出现上面说的一大串错误了,这个程序是我从书上抄的,应该是哪里配置没有对哦
      

  4.   

    将bea/weblogic81/service/lib下面的
    weblogic.jar , wsclient81.jar放如环境变量即可 
    这个名字是8.1版本的对应的9 或 10 的自己找jar包路径是一样的 前提是你weblogic已经启动
      

  5.   

    目录里只有weblogic.jar但是没有wsclient.jar类似的包了。我仔细看了下weblogic启动时的命令提示符里面的内容,上面有把bea/weblogic92/server/lib内的一部分内容加入classpath
      

  6.   

    是不是虚拟机把"t3://localhost:7001"这个URL当成普通的http了才会出现java.lang.AssertionError: An error occurred while rerieving the network addresses for this machine. The most likely cause is an error in the network configuration of this machine.这个错误啊,怎么就没有哪位高手知道啊 
      

  7.   

    哎  没办法只好换了一个8.1版本的,7楼的说要加weblogic.jar和wsclient81.jar到环境变量,但是我只加了weblogic.jar怎么也能行啊,而9.2版本的只加这个却不行。哪位牛人来个解释啊
      

  8.   

      从问题可以看出是找不到weblogic.jndi.WLInitialContextFactory类,开始我认为是classpath环境变量设置错误,但是用winrar打开weblogic.jar发现这个类的确在这个JAR包中,就不知道是什么原因了.到网上找了好久没有找到解决办法.今天起床再来看这个问题的时候,忽然想起老师以前讲过在netbeans中的项目中加入JAR包,于是在eclipse中找了一下,发现可以实现.具体步骤如下:在项目上点鼠标右键,选properties,然后选中左边的Java Build Path,选中右边的Libraries,选择Add External JARs,找到D:\bea\wlserver_10.0\server\lib\weblogic.jar,加入后点OK,就可以了.这时再运行上面的程序,就没有问题了.运行完成后,在weblogic的JNDI Tree里可以看到有一个接点是test,它的内容是"Hello WebLogic JNDI".        在网上找了几天,都没有解决掉这个问题,今天终于解决了,实在是高兴.posted on 2007-08-02 10:24 
    所有权归————寂寞沙冷