3 Replies Latest reply on Aug 24, 2010 9:57 AM by Noelia Delgado

    javax.naming.NoInitialContextException: Cannot instantiate class

    Noelia Delgado Newbie

      Hi, I have a problem when I want to run my application's jar, it's a standalone app and I don't have this problem when I run it into Eclipse.

      I'm using Jboss 5.1.0GA, maven 2.2.1 and JDK 1.6.18.

       

      PS C:\Workspace\hre\target> java -jar AppClient.jar
      java.exe : javax.naming.NoInitialContextException: Cannot instantiate class: or
      g.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoun
      dException: org.jnp.interfaces.NamingContextFactory]
      At line:1 char:5
      + java <<<<  -jar AppClient.jar
          + CategoryInfo          : NotSpecified: (javax.naming.No...ContextFactory]
         :String) [], RemoteException
          + FullyQualifiedErrorId : NativeCommandError

          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
          at javax.naming.InitialContext.init(InitialContext.java:223)
          at javax.naming.InitialContext.<init>(InitialContext.java:197)
          at util.Contexto.<init>(Contexto.java:22)
          at mesa_entrada.IdPaciente.setContexto(IdPaciente.java:1627)
          at mesa_entrada.IdPaciente.<init>(IdPaciente.java:185)
          at principal.Escritorio$2.actionPerformed(Escritorio.java:206)
          at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
          at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2
      318)
          at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.ja
      va:387)
          at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)

          at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonList
      ener.java:236)
          at java.awt.Component.processMouseEvent(Component.java:6263)
          at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
          at java.awt.Component.processEvent(Component.java:6028)
          at java.awt.Container.processEvent(Container.java:2041)
          at java.awt.Component.dispatchEventImpl(Component.java:4630)
          at java.awt.Container.dispatchEventImpl(Container.java:2099)
          at java.awt.Component.dispatchEvent(Component.java:4460)
          at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
          at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
          at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
          at java.awt.Container.dispatchEventImpl(Container.java:2085)
          at java.awt.Window.dispatchEventImpl(Window.java:2478)
          at java.awt.Component.dispatchEvent(Component.java:4460)
          at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
          at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.
      java:269)
          at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.jav
      a:184)
          at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.
      java:174)
          at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
          at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
          at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFa
      ctory
          at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:247)
          at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:4
      6)
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
          ... 32 more

       

      This is my code:

       

      public Contexto() throws NamingException{


      Properties env = new Properties();

       

      // Try with a login that should succeed
      env.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");

      env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");

      env.setProperty("java.naming.provider.url", "localhost:1099");


      env.setProperty(Context.SECURITY_CREDENTIALS, "");


      env.setProperty(Context.SECURITY_PRINCIPAL, "");

      env.setProperty(Context.SECURITY_PROTOCOL, "java:/jaas/App");


      this.ctx = new InitialContext(env);
      }

       

      I added my server.log


      If anyone can help me I would appreciate it.

       

      Thanks

        • 1. Re: javax.naming.NoInitialContextException: Cannot instantiate class
          Peter Johnson Master

          What all is in your AppClient.jar file? When using the -jar commandl ine option, the classpath is ignored and only the indicated JAR file is available on the classpath. However, when you run a client against the app server, you must include the JAR files in the jboss_home/client directory in the classpath.

          • 2. Re: javax.naming.NoInitialContextException: Cannot instantiate class
            Noelia Delgado Newbie

            Hi, how  I can include jbossall-client.jar in my pom? I have tried:

             

            <dependency>
            <groupId>org.jboss.jbossas</groupId>
            <artifactId>jboss-as-client</artifactId>
            <type>pom</type>
            <version>5.1.0.GA</version>
            </dependency>

            but it doesn't work

             

            My app's pom.xml is:

            <

            project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

             

            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

             

            <modelVersion>4.0.0</modelVersion>

             

            <groupId>unsj</groupId>

             

            <artifactId>hre-ui</artifactId>

             

            <version>0.0.1-SNAPSHOT</version>

             

            <name>AppClient</name>

             

            <packaging>jar</packaging>

             

             

            <dependencies>

             

            <dependency>

             

            <groupId>unsj</groupId>

             

            <artifactId>hre_ejb</artifactId>

             

            <version>0.0.1-SNAPSHOT</version>

             

            <type>ejb</type>

             

            </dependency>

             

             

            <dependency>

             

            <groupId>unsj</groupId>

             

            <artifactId>utiles</artifactId>

             

            <version>0.0.1-SNAPSHOT</version>

             

            </dependency>

             

             

            </dependencies>

             

            <build>

             

            <plugins>

             

             

            <plugin>

             

            <groupId>org.apache.maven.plugins</groupId>

             

            <artifactId>maven-compiler-plugin</artifactId>

             

            <version>2.0.2</version>

             

            <configuration>

             

            <source>1.6</source>

             

            <target>1.6</target>

             

            </configuration>

             

            </plugin>

             

             

            <plugin>

             

            <groupId>org.apache.maven.plugins</groupId>

             

            <artifactId>maven-jar-plugin</artifactId>

             

            <version>2.3.1</version>

             

            <configuration>

             

            <archive>

             

            <manifest>

             

            <addClasspath>true</addClasspath>

             

            <classpathPrefix>lib/</classpathPrefix>

             

            <mainClass>principal.Escritorio</mainClass>

             

            </manifest>

             

            </archive>

             

            </configuration>

             

            </plugin>

             

             

            <plugin>

             

            <groupId>org.freehep</groupId>

             

            <artifactId>freehep-jarjar-plugin</artifactId>

             

            <executions>

             

            <execution>

             

            <goals>

             

            <goal>jarjar</goal>

             

            </goals>

             

            </execution>

             

            </executions>

             

            <!--

            El siguiente trozo debemos ponerlo si queremos que se metan dentro

            del jar TODOS los jar de los que dependemos de forma no explicita

            en el pom.xml

            -->

             

            <configuration>

             

            <addTransitiveDependencies>false</addTransitiveDependencies>

             

            </configuration>

             

            </plugin>

             

             

            </plugins>

             

            <finalName>AppClient</finalName>

             

            </build>

             

            <pluginRepositories>

             

            <pluginRepository>

             

            <id>freehep-maven</id>

             

            <name>Maven FreeHEP</name>

             

            <url>http://java.freehep.org/maven2</url>

             

            </pluginRepository>

             

            </

            project>

             

            Thanks

            • 3. Re: javax.naming.NoInitialContextException: Cannot instantiate class
              Noelia Delgado Newbie

              Ok, this solves the problem

              http://www.javahelp.info/2010/01/27/get-the-right-dependencies-for-jboss-5-client-and-maven/

               

              but now I have a new one:

               

              PS C:\Workspace\hre\target> java -jar AppClient.jar
              java.exe : javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
              At line:1 char:5
              + java <<<<  -jar AppClient.jar
                  + CategoryInfo          : NotSpecified: (javax.naming.Na...wableException]:String) [], RemoteException
                  + FullyQualifiedErrorId : NativeCommandError

                  at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1504)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                  at javax.naming.InitialContext.lookup(InitialContext.java:392)
                  at util.Contexto.getInterfazRemota(Contexto.java:29)
                  at mesa_entrada.IdPaciente.getInterfazRemota(IdPaciente.java:1635)
                  at mesa_entrada.IdPaciente.setInterfazRemotaPaciente(IdPaciente.java:1645)
                  at mesa_entrada.IdPaciente$8.actionPerformed(IdPaciente.java:1031)
                  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
                  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
                  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
                  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
                  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
                  at java.awt.Component.processMouseEvent(Component.java:6263)
                  at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
                  at java.awt.Component.processEvent(Component.java:6028)
                  at java.awt.Container.processEvent(Container.java:2041)
                  at java.awt.Component.dispatchEventImpl(Component.java:4630)
                  at java.awt.Container.dispatchEventImpl(Container.java:2099)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
                  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
                  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
                  at java.awt.Container.dispatchEventImpl(Container.java:2085)
                  at java.awt.Window.dispatchEventImpl(Window.java:2478)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
                  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
              Caused by: java.lang.reflect.UndeclaredThrowableException
                  at $Proxy0.createProxyBusiness(Unknown Source)
                  at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
                  at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObject
              Factory.java:79)
                  at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:158)
                  at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
                  at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
                  at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
                  ... 32 more
              Caused by: java.lang.ClassNotFoundException: org.jboss.aspects.tx.ClientTxPropagationInterceptor
                  at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)
                  at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:86)
                  at java.lang.Class.forName0(Native Method)
                  at java.lang.Class.forName(Class.java:247)
                  at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:179)
                  at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
                  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                  at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1667)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323)
                  at java.io.ObjectInputStream.defaultReadFields
              (ObjectInputStream.java:1947)

                  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
                  at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:119)
                  at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                  at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)

                  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
                  at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)
                  at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)
                  at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)
                  at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1220)
                  at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:850)
                  at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:165)
                  at org.jboss.remoting.Client.invoke(Client.java:1724)
                  at org.jboss.remoting.Client.invoke(Client.java:629)
                  at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
                  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                  at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)
                  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                  at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                  at $Proxy0.createProxyBusiness(Unknown Source)
                  at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
                  at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObject
              Factory.java:79)
                  at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:158)
                  at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
                  at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
                  at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
                  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
                  at javax.naming.InitialContext.lookup(InitialContext.java:392)
                  at util.Contexto.getInterfazRemota(Contexto.java:29)
                  at mesa_entrada.IdPaciente.getInterfazRemota(IdPaciente.java:1635)
                  at mesa_entrada.IdPaciente.setInterfazRemotaPaciente(IdPaciente.java:1645)
                  at mesa_entrada.IdPaciente$8.actionPerformed(IdPaciente.java:1031)
                  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
                  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
                  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
                  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
                  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
                  at java.awt.Component.processMouseEvent(Component.java:6263)
                  at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
                  at java.awt.Component.processEvent(Component.java:6028)
                  at java.awt.Container.processEvent(Container.java:2041)
                  at java.awt.Component.dispatchEventImpl(Component.java:4630)
                  at java.awt.Container.dispatchEventImpl(Container.java:2099)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
                  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
                  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
                  at java.awt.Container.dispatchEventImpl(Container.java:2085)
                  at java.awt.Window.dispatchEventImpl(Window.java:2478)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
                  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
                  at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
                  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                  at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)
                  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                  at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
                  ... 39 more

              java.lang.NullPointerException

                  at mesa_entrada.IdPaciente$8.actionPerformed(IdPaciente.java:1043)
                  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
                  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
                  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
                  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
                  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
                  at java.awt.Component.processMouseEvent(Component.java:6263)
                  at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
                  at java.awt.Component.processEvent(Component.java:6028)
                  at java.awt.Container.processEvent(Container.java:2041)
                  at java.awt.Component.dispatchEventImpl(Component.java:4630)
                  at java.awt.Container.dispatchEventImpl(Container.java:2099)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
                  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
                  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
                  at java.awt.Container.dispatchEventImpl(Container.java:2085)
                  at java.awt.Window.dispatchEventImpl(Window.java:2478)
                  at java.awt.Component.dispatchEvent(Component.java:4460)
                  at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
                  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

               

              Any idea?