sasidharnet 0 Newbie Poster

This is sasidhar.
I am getting problem with JNDI.
please help to solve this problem.

This is the program I used to work on JNDI.
I am using weblogic 10.0

import javax.naming.*;
import java.rmi.*;
import java.util.*;

public class UseJndi{
    public  static void main(String args[]){
        try{
            Hashtable h = new Hashtable();
            h.put(Context.INITIAL_CONTEXT_FACTORY,
                "weblogic.jndi.WLInitialContextFactory");
            h.put(Context.PROVIDER_URL, "t3://localhost:7001");
            h.put(Context.SECURITY_PRINCIPAL, "admin");//user
            h.put(Context.SECURITY_CREDENTIALS, "inetadmin"); 
            Context ic = new InitialContext(h);
            System.out.println(" initial context = "+ ic);
            NamingEnumeration ne = ic.listBindings("");
            while (ne.hasMore()) {
                Binding b = (Binding)ne.next();
                System.out.println( b.getName());
                System.out.println(b.getObject());
            }
        }catch (Exception e){}
    }
}

It is compiling and when I am trying to run this it is showing this problem

E:\programs>java UseJndi
Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/kernel/Kerne
lStatus
        at weblogic.jndi.Environment.<clinit>(Environment.java:73)
        at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialCont
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 UseJndi.main(UseJndi.java:18)

please give reply to this problem.

Dani AI

Generated

For : the runtime error you see means the WebLogic runtime classes required by weblogic.jndi.WLInitialContextFactory are not on the Java process classpath. NoClassDefFoundError for weblogic.kernel.KernelStatus is a linkage error (not an Exception), so your catch (Exception e) { } will not catch it — that explains why the JVM prints the stack trace.

Fixes (pick one):

  • Recommended: create and use the WebLogic full client JAR. From your WebLogic installation run the jar-builder in WL_HOME/server/lib to produce wlfullclient.jar, then add that jar to your client classpath. Example runs:

    cd %WL_HOME%\server\lib
    java -jar wljarbuilder.jar

    Then launch your program with:

    java -cp .;%WL_HOME%\server\lib\wlfullclient.jar UseJndi
  • Quick/test option: add the server runtime jar directly (not recommended for production). Example:

    java -cp .;%WL_HOME%\server\lib\weblogic.jar UseJndi

Troubleshooting tips:

  • Verify the class exists inside the JAR you put on the classpath (use jar tf + findstr/grep to search for weblogic/kernel/KernelStatus).

  • Run the client with -verbose:class to see which JAR provides which classes.

  • For debugging, avoid swallowing errors; change the catch to print the stack trace so you see linkage and class-loading problems early:

    } catch (Throwable t) { t.printStackTrace(); }

Notes and cautions:

  • wlclient.jar alone may not contain all server kernel classes; wlfullclient.jar is the safer packaged client artifact.
  • Don’t ship weblogic.jar with a distributed client — use the generated full client jar for standalone applications.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.