在尝试执行我的jar文件时,我得到一个异常:
javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory
[Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]
Run Code Online (Sandbox Code Playgroud)
我想这是类路径上某种丢失的库.谁能告诉我哪个jar文件丢失了?我无法在任何地方找到weblogic.jndi.WLInitialContextFactory类...
谢谢!
PS:我已经包含了weblogic 10.0 jar.
Nun*_*ado 14
检查server/lib /文件夹以查找wliclient.jar.
使用Weblogic 12.1.3,您可以在此处找到它:
${INSTALL_DIR}/inventory/wlserver/server/lib/wlclient.jar
小智 6
步骤1:
去吧E:\weblogic81\user_projects\domains\mydomain.然后输入Setenv命令.如下
E:\weblogic81\user_projects\domains\mydomain>setenv
Run Code Online (Sandbox Code Playgroud)
第2步:
Weblogic.jar客户端应用程序需要该文件.它可能包含在以下路径中E:\weblogic81\weblogic81\server\lib\weblogic.jar.因此,请设置此文件夹的类路径,或将此weblogic.jar文件复制到应用程序文件夹中,以便首先为您的应用程序提供weblogic.jar文件.
E:\weblogic81\user_projects\domains\mydomain>set CLASSPATH=%CLASSPATH%;E:\weblogic81\weblogic81\server\lib;.
Run Code Online (Sandbox Code Playgroud)
第3步:
如上所示转到命令提示符下的domain文件夹并设置classpath.为了不打扰其他类路径,将classpath设置为:
set CLASSPATH=%CLASSPATH%;E:\weblogic81\weblogic81\server\lib;.
Run Code Online (Sandbox Code Playgroud)
Here(.)dot表示当前目录的set classpath.
第4步:
在classpath设置后运行命令STARTWEBLOGIC如下:
E:\weblogic81\user_projects\domains\mydomain>STARTWEBLOGIC
Run Code Online (Sandbox Code Playgroud)
第5步:
不要登录weblogic服务器.如果您已经登录,只需注销并在myeclipse或其他IDE中编写以下代码.
第6步:
package directory.service;
import java.util.*;
import weblogic.jndi.*;
import java.io.FileInputStream;
import javax.naming.*;
public class GetInitContext {
/**
* @param args
*/
public static void main(String[] args) {
try{
weblogic.jndi.Environment env=new weblogic.jndi.Environment();
weblogic.jndi.Environment environment = new weblogic.jndi.Environment();
environment.setInitialContextFactory(
weblogic.jndi.Environment.DEFAULT_INITIAL_CONTEXT_FACTORY);
env.setProviderUrl("t3://localhost:7001");
env.setSecurityPrincipal("agni");
env.setSecurityCredentials("agnidevam");
Context context=env.getInitialContext();
System.out.println("got the initial context for weblogic server---> "+context);
context.createSubcontext("sone");
context.bind("agni one",new Integer(10));
context.createSubcontext("sone/sctwo");
context.bind("agni two",new Integer(20));
context.createSubcontext("sone/sctwo/scthree");
context.bind("agni three",new Integer(30));
System.out.println("subcontex object created please check in admin server for more details");
}
catch(Exception e){
System.out.println("file inputstream exception ---> "+e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
第7步:
执行上面的代码并登录weblogic并右键单击,myserver>view jndi tree>找到绑定对象信息.