Where is class weblogic.jndi.WLInitialContextFacto

2019-04-05 09:21发布

when trying to execute my jar file I get an exception:

javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory 
[Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]

I guess this is some kind of missing library on the classpath. Can anyone tell me which jar-file is missing? I can't find the class weblogic.jndi.WLInitialContextFactory anywhere...

Thanks!

P.S.: I already have weblogic 10.0 jar included.

8条回答
爷的心禁止访问
2楼-- · 2019-04-05 09:45

in version 12c it is located in weblogic-classes.jar in your lib directory:

C:\wls1213\wlserver\server\lib

查看更多
劫难
3楼-- · 2019-04-05 09:46

Step 1:

Go to E:\weblogic81\user_projects\domains\mydomain. Then type Setenv command. As follows

E:\weblogic81\user_projects\domains\mydomain>setenv 

Step 2:

Weblogic.jar file is needed by your client application. It may contain in the following path E:\weblogic81\weblogic81\server\lib\weblogic.jar. so set the classpath for the this folder or copy this weblogic.jar file into your application-folder so that weblogic.jar file is available to your application first.

E:\weblogic81\user_projects\domains\mydomain>set CLASSPATH=%CLASSPATH%;E:\weblogic81\weblogic81\server\lib;.

Step 3:

Go to domain folder in command prompt as shown above and set classpath. To not to disturb other classpaths set classpath as:

set CLASSPATH=%CLASSPATH%;E:\weblogic81\weblogic81\server\lib;.

Here (.) dot represents set classpath to current directory.

Step 4:

After classpath set run command STARTWEBLOGIC as follows:

E:\weblogic81\user_projects\domains\mydomain>STARTWEBLOGIC 

Step 5:

Do not login to weblogic server. If you are already login just log out and write the following code in myeclipse or some other IDE.

Step 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);
        }
    }

}

Step 7:

Execute the above code and login to weblogic and right click on myserver>view jndi tree> you find the bound objects information.

查看更多
登录 后发表回答