problem with Karaf jndi feature

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

problem with Karaf jndi feature

Hello all,

I am using apache karaf 3.0.3.

I just followed the guide of Karaf regarding JNDI,
installed the feature

feature:install jndi

The guide states that

You have two parts in the Apache Karaf JNDI support:

a fully compliant implementation of the OSGi Alliance JNDI Service specification.
a more "regular" JNDI context, containing different names that you can administrate.

When i execute


I got

JNDI Name         | Class Name                                    
osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl

instead of

JNDI Name         | Class Name
osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
jndi/service      | org.apache.karaf.jndi.internal.JndiServiceImpl

as the guide says

Also when i try to do the following to test the jndi from outside OSGI


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Main {

    public static void main(String[] args) {
        // write your code here
        try {
            Context ctx = new InitialContext();
            Object service = (Object)ctx.lookup("osgi:service/jndi");
            if(service != null){
                System.out.println("No service instance received");
        } catch (NamingException e) {


i receive the following error stack trace

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(
        at javax.naming.InitialContext.getDefaultInitCtx(
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(
        at javax.naming.InitialContext.lookup(
        at Test.main(

Also if i use Karaf 4.0.0 M2 when i install the jndi feature the jndi:names command shows nothing

Anyone know how to resolve this issue, i need to access the osgi jndi from outside osgi.

Thank you in advance,