11 Replies Latest reply on Oct 13, 2009 9:27 AM by wkzk

    NoClassDefFound Exception connecting to JBM 1.4.0

      Hi,

      I am writing a standalone java client to connect to JBM 1.4.0 queue.

      Following is my code:

      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming: org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "jnp://host:port");

      Context jndiContext = new InitialContext(p);

      //get reference to the ConnectionFactory
      ConnectionFactory connectionFactory =
      (ConnectionFactory) jndiContext.lookup("ClusteredConnectionFactory");

      //get reference to JMS destination
      javax.jms.Queue destination =
      (javax.jms.Queue) jndiContext.lookup("queue/queue1");

      Connection connection = connectionFactory.createConnection("user","pwd");

      I am getting exception at the createConnection:
      Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.jboss.remoting.util.TimerUtil
      at org.jboss.remoting.ConnectionValidator.start(ConnectionValidator.java:503)
      at org.jboss.remoting.ConnectionValidator.addConnectionListener(ConnectionValidator.java:345)
      at org.jboss.remoting.Client.addConnectionListener(Client.java:385)
      at org.jboss.remoting.Client.addConnectionListener(Client.java:355)
      at org.jboss.remoting.Client.addConnectionListener(Client.java:343)
      at org.jboss.jms.client.remoting.JMSRemotingConnection.addConnectionListener(JMSRemotingConnection.java:462)
      at org.jboss.jms.client.container.StateCreationAspect.handleCreateConnectionDelegate(StateCreationAspect.java:101)
      at org.jboss.aop.advice.org.jboss.jms.client.container.StateCreationAspect_z_handleCreateConnectionDelegate_1027049.invoke(StateCreationAspect_z_handleCreateConnectionDelegate_1027049.java)
      at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
      at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.createConnectionDelegate(ClientConnectionFactoryDelegate.java)
      at org.jboss.jms.client.container.ClusteringAspect.handleCreateConnectionDelegate(ClusteringAspect.java:134)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.aop.advice.PerInstanceAdvice.invoke(PerInstanceAdvice.java:122)
      at org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientClusteredConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
      at org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate.createConnectionDelegate(ClientClusteredConnectionFactoryDelegate.java)
      at org.jboss.jms.client.JBossConnectionFactory.createConnectionInternal(JBossConnectionFactory.java:205)
      at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:87)
      at jmsremoteclient.TestMessageProducer.main(TestMessageProducer.java:44)

      I have included the jbossall-client.jar in the classpath so I am not sure why it's getting class definition not found exception.

      My classpath is as followed:
      jboss-aop.jar
      jboss-remoting.jar
      javassist.jar
      trove.jar
      jbossall-client.jar
      jboss-mdr.jar


      Can someone also explain how the JBM class loading works with AOP , jboss-remoting.jar and jbossall-client.jar?

      thanks in advance,
      David

        • 1. Re: NoClassDefFound Exception connecting to JBM 1.4.0
          gaohoward

          JBM 1.4 doesn't have any special class loading to work with AOP, jboss-remoting.jar etc. Take a look at the examples that comes with jbm 1.4. The correct classpath can be found in the build.xml files.

          • 2. Re: NoClassDefFound Exception connecting to JBM 1.4.0

            Based on JBM 1.4 documentation, the jar needed for remote client is:

            jboss-aop.jar
            jboss-remoting.jar
            jbossall-client.jar
            jboss-messaging-client.jar

            jboss-mdr.jar <- I had to add this one to get the signature class
            javassist.jar
            trove.jar


            (http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/userguide-1.4.0.SP3/html_single/index.html#inst.remoteclient)

            I included the jars in the order above and verified all the jars are in the right version. (JBoss 4.3.0GA) However, I am still getting the same exception. Any help would be appreciated.

            • 3. Re: NoClassDefFound Exception connecting to JBM 1.4.0
              peterj

              Try adding client/log4j.jar and see if that helps.

              If that does not work, add "-verbose:class" to the JVM options on your client's command line and run it again. This option prints out the JAR file location for each class loaded; perhaps that will give use some clue as to the problem. Also, post the full command line you used.

              • 4. Re: NoClassDefFound Exception connecting to JBM 1.4.0
                timfox

                My guess is the user has a mix and match of different versions on client and server side.

                • 5. Re: NoClassDefFound Exception connecting to JBM 1.4.0

                  Peter,

                  Adding log4j.jar causes exception in the ConnectionFactory lookup which is before where the other exception happens.

                  Exception in thread "main" java.lang.NoSuchFieldError: TRACE
                  at org.jboss.logging.Log4jLoggerPlugin.isTraceEnabled(Log4jLoggerPlugin.java:85)


                  I removed the log4j.jar and I have added verbose:class in my run command but the log doesn't show much insight for me:

                  [Loaded org.jboss.aop.advice.org.jboss.jms.client.container.StateCreationAspect_z_handleCreateSessionDelegate_1027049 from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.client.container.SessionAspect from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.delegate.Ack from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded javax.jms.IllegalStateException from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded javax.jms.TransactionInProgressException from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.delegate.Cancel from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.client.state.HierarchicalStateSupport from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.client.state.SessionState from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.delegate.DeliveryInfo from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.aop.advice.org.jboss.jms.client.container.SessionAspect_z_handleCreateConnectionConsumer_1027049 from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener from file:/C:/JMSRemoteClient/lib/jbossall-client.jar]
                  [Loaded sun.reflect.GeneratedMethodAccessor1 from __JVM_DefineClass__]
                  Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.jboss.remoting.util.TimerUtil
                  at org.jboss.remoting.ConnectionValidator.start(ConnectionValidator.java:503)


                  TimerUtil is in jboss-remoting.jar as well as jbossall-client.jar. I am not sure why the JVM couldn't find. (My JVM is 1.6. If I switch to 1.5, I get NoClassDefFoundError exception at the same place but without the message suggesting the missing class name).

                  Tim,

                  I think the client jar is the right version because I am able to use the same set of jars to connect to the JBM queue via Hermes. Not sure why a standalone java client would act any difference...

                  • 6. Re: NoClassDefFound Exception connecting to JBM 1.4.0
                    peterj

                    You should be using jboss_home/client/log4j.jar. Looks like you are using an older version of log4j, before they added in trace level support.

                    I am suspecting the the log4j.jar file bacause TimerUtil imports a class from there, and the error text is "Could not initialize". This implies, to me, a missing dependency.

                    • 7. Re: NoClassDefFound Exception connecting to JBM 1.4.0

                      Thanks Peter for the quick response.

                      The log4j is from the client folder and it is apache version 1.2.14. Based on the following post, it should resolve the issue.

                      http://lists.jboss.org/pipermail/jboss-user/2008-February/108795.html

                      However, if I don't include log4j.jar, I do not get exception (java.lang.NoSuchFieldError: TRACE).

                      What am I missing?

                      • 8. Re: NoClassDefFound Exception connecting to JBM 1.4.0
                        peterj

                        I moved my messaging app over to EAP 4.3, and there is what I had to add to my client's classpath (beyond the JAR files for my app):

                        jboss-eap-4.3\jboss-as\client\jbossall-client.jar
                        jboss-eap-4.3\jboss-as\server\default\deploy\jboss-aop-jdk50.deployer\jboss-aop-jdk50.jar
                        jboss-eap-4.3\jboss-as\client\javassist.jar
                        jboss-eap-4.3\jboss-as\client\trove.jar
                        jboss-eap-4.3\jboss-as\client\commons-logging.jar
                        jboss-eap-4.3\jboss-as\client\log4j.jar

                        • 9. Re: NoClassDefFound Exception connecting to JBM 1.4.0


                          Please discard my last post. What was in the classpath was the old log4j.jar and the exception went away after I fixed the issue.

                          Peter you were right on, the TimerUtil class failed to initialize due to the log4j.jar. Thanks!

                          • 10. Re: NoClassDefFound Exception connecting to JBM 1.4.0

                            Hi,

                            The standalone client works fine until I import the standalone code as a utility jar into a application running on Sun Application Server 8.2.

                            I run into NoClassDefFound Exception again:

                            Caused by: java.lang.NoClassDefFoundError
                            at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.createClient(ClientConnectionFactoryDelegate.java:298)
                            at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$getClientAOPStack$aop(ClientConnectionFactoryDelegate.java:228)
                            at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.getClientAOPStack(ClientConnectionFactoryDelegate.java)
                            at org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientClusteredConnectionFactoryDelegate$getClientAOPStack$aop(ClientClusteredConnectionFactoryDelegate.java:242)
                            at org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate.getClientAOPStack(ClientClusteredConnectionFactoryDelegate.java)
                            at org.jboss.jms.client.ClientAOPStackLoader.load(ClientAOPStackLoader.java:75)
                            at org.jboss.jms.client.JBossConnectionFactory.createConnectionInternal(JBossConnectionFactory.java:192)
                            at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:87)
                            at jmsremoteclient.TestMessageProducer.(TestMessageProducer.java:43)

                            TestMessageProducer is the class where I try to initiate the connection to JBM. The exception doesn't suggest the class name and therefore made it harder to debug. (I did included log4j.jar)

                            Any suggestions?

                            • 11. Re: NoClassDefFound Exception connecting to JBM 1.4.0

                              Hi. I got the same exception, and I understand what is going on.

                              Let me make sure that
                              I have no choice with older log4j version even now.

                              No work around?

                              Thanks in advance.

                              Shige