5 Replies Latest reply on Feb 10, 2012 5:26 AM by VITHUN VENGOPALAN Branched to a new discussion.

    jboss-as-7.0.1.Final - Not able to get context.

    Aslam Mohd Newbie

      Hi,

       

      I am not able to initialize context in AS7. Please help. Following is the piece of code am trying.

       

       

      import java.util.Properties;

       

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      public class Main {

       

          public static void main(String[] args) throws NamingException {

              System.out.println(">>>>>>>>>>>>>>>>");

              // org.jnp.interfaces.NamingContextFactory - jboss 5

              // org.jboss.as.naming.InitialContextFactory - jboss 7

              Properties props = new Properties();

              props.setProperty(Context.INITIAL_CONTEXT_FACTORY,    "org.jboss.as.naming.InitialContextFactory");

              props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");

              InitialContext ctx = new InitialContext(props);

       

          }

       

      }

       

      I get following exception.

       

      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.as.naming.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.as.naming.InitialContextFactory]

          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 com.pcs.obix.Main.main(Main.java:21)

      Caused by: java.lang.ClassNotFoundException: org.jboss.as.naming.InitialContextFactory

          at java.net.URLClassLoader$1.run(Unknown Source)

          at java.security.AccessController.doPrivileged(Native Method)

          at java.net.URLClassLoader.findClass(Unknown Source)

          at java.lang.ClassLoader.loadClass(Unknown Source)

          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

          at java.lang.ClassLoader.loadClass(Unknown Source)

          at java.lang.Class.forName0(Native Method)

          at java.lang.Class.forName(Unknown Source)

          at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

          ... 5 more