0 Replies Latest reply on Jul 31, 2007 12:50 AM by pan sadsfd

    MDB run error

    pan sadsfd Newbie

      JMSClient.java

      package com;

      import javax.jms.JMSException;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      public class JMSClient {

      /**
      * @param args
      */

      private QueueConnection queueConnection=null;
      private QueueSender queueSender=null;
      private QueueSession queueSession=null;
      private Queue queue=null;

      private TextMessage msg = null;

      public JMSClient(String[] argv) throws Exception {

      try {
      InitialContext ctx=new InitialContext();

      QueueConnectionFactory factory=(QueueConnectionFactory)ctx.lookup("java:comp:/env/jms/QueueConnectionFactory");
      queueConnection = factory.createQueueConnection();


      // Create a non-transacted JMS Session
      queueSession =queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

      queue = (Queue) ctx.lookup("Queue/TempMDB");

      queueSender = queueSession.createSender(queue);

      msg = queueSession.createTextMessage();

      queueConnection.start();

      } catch (Exception e) {
      System.err.println(
      "Error while attempting to "
      + "connect to the server and look up the JMS"
      + " QueueConnectionFactory.");
      System.err.println(
      "Please make sure that you have"
      + " deployed the JMS Queue and specified the correct"
      + " server URL.");

      e.printStackTrace();

      throw e;
      }
      }

      public void send(String message) throws JMSException {
      try {
      msg.setText(message);
      queueSender.send(msg);
      } catch (JMSException e) {
      System.err.println(
      "Exception raised while sending" + "to queue: " );
      e.printStackTrace();
      throw e;
      }
      }

      public static void main(String[] argv) throws Exception {

      JMSClient tmsc = new JMSClient(argv);
      tmsc.send("Hello");
      }

      }

      ----------------------------------------------------------------------------------------------------------------------

      TempMDB.java

      package com;

      import javax.ejb.EJBException;
      import javax.ejb.MessageDrivenBean;
      import javax.ejb.MessageDrivenContext;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.TextMessage;

      public class TempMDB implements MessageDrivenBean, MessageListener {

      /** The MessageDrivenContext */
      private MessageDrivenContext context;

      public TempMDB() {
      // TODO Auto-generated constructor stub
      }

      public void ejbRemove() throws EJBException {
      // TODO Auto-generated method stub

      }

      public void setMessageDrivenContext(MessageDrivenContext newContext)
      throws EJBException {
      context = newContext;
      }

      public void onMessage(Message inMessage) {
      // TODO Auto-generated method stub

      TextMessage msg = null;

      try {

      if (inMessage instanceof TextMessage) {

      msg = (TextMessage) inMessage;

      System.out.println

      ("MESSAGE BEAN: Message received: "

      + msg.getText());

      } else {

      System.out.println

      ("Message of wrong type: "

      + inMessage.getClass().getName());

      }

      } catch (JMSException e) {

      e.printStackTrace();



      } catch (Throwable te) {

      te.printStackTrace();

      }



      }

      public void ejbCreate() {
      }

      }

      ----------------------------------------------------------------------------------------------------------------------
      E:\jboss-4.0.0\server\default\deploy\jms\jbossmq2-destinations-service.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- Destination without a configured SecurityManager or without a
      a SecurityConf will default to role guest with read=true, write=true,
      create=false.
      -->

      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager





      ----------------------------------------------------------------------------------------------------------------------



      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>TempMDB</ejb-name>
      <ejb-class>com.TempMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      <subscription-durability>NonDurable</subscription-durability>
      </message-driven-destination>
      <resource-ref>

      <res-ref-name>jms/QCF</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      ----------------------------------------------------------------------------------------------------------------------


      jboss.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

      <enterprise-beans>
      <message-driven>
      <ejb-name>TempMDB</ejb-name>
      <destination-jndi-name>queue/TempMDB</destination-jndi-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <jndi-name>QueueConnectionFactory</jndi-name>
      </resource-ref>
      </message-driven>


      </enterprise-beans>


      ----------------------------------------------------------------------------------------------------------------------
      After deploying the project and run "JMSClient.java", it occured the error which are the following.


      Error while attempting to connect to the server and look up the JMS QueueConnectionFactory.
      Please make sure that you have deployed the JMS Queue and specified the correct server URL.
      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ]
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.(InitialContext.java:175)
      at com.JMSClient.(JMSClient.java:30)
      at com.JMSClient.main(JMSClient.java:77)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
      ... 5 more
      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ]
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.(InitialContext.java:175)
      at com.JMSClient.(JMSClient.java:30)
      at com.JMSClient.main(JMSClient.java:77)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
      ... 5 more


      I have tried the project all day,but it occured all the time.People who is researching MDB ,please help me.