Compilation error In RAD 8.5 - JMS Message Producer client to post message to websphere Queue

故事扮演 提交于 2019-12-25 12:42:11

问题


I am trying to write a java client which posts a message to a Queue.I am using Java 7 and RAD 8.5. RAD is complaining that some classes cannot be resolved.Please help me fix it.

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import com.ibm.msg.client.jms.JmsConnectionFactory;
import com.ibm.msg.client.jms.JmsDestination;

public class JMS_JNDI_Queue_Producer {

private static String initialContextUrl = "my url";
private static String connectionFactoryFromJndi = "my connection factory";
private static String destinationFromJndi = "my destination";

public static void main(String[] args) {

    // Variables
    Connection connection = null;
    Session session = null;
    Destination destination = null;
    MessageProducer producer = null;

    try {

        String contextFactory = "com.sun.jndi.ldap.LdapCtxFactory";
        Hashtable<String, String> environment = new Hashtable<String, String>();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
        environment.put(Context.PROVIDER_URL, initialContextUrl);
        Context context = new InitialDirContext(environment);
        System.out.println("Initial context found!");

        // Lookup the connection factory
        JmsConnectionFactory cf = (JmsConnectionFactory) context.lookup(connectionFactoryFromJndi);
        // Lookup the destination
        destination = (JmsDestination) context.lookup(destinationFromJndi);

        // Create JMS objects
        connection = cf.createConnection("mqclient","busclient");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(destination);

        // Create a message
        long uniqueNumber = System.currentTimeMillis() % 1000;
        TextMessage message = session.createTextMessage("JmsProducer: Your lucky number today is "
                + uniqueNumber);

         connection.start(); 
         System.out.println("JMS client connection started!"); 
         producer.send(message);
         System.out.println("Sent message:\n" + message);
         producer.close();
         System.out.println("Producer closed.");
         session.close();
         System.out.println("Session closed."); 
         connection.close(); 
         System.out.println("JMS client connection closed."); 

    } catch (JMSException ex) { 
        ex.printStackTrace(); 
    }    catch (NamingException ne) {
        ne.printStackTrace(); 
    } catch (Exception ex){ 
        ex.printStackTrace(); 
    } 
} 
} 

So RAD is complaining that it cannot find classes com.ibm.msg.client.jms.JmsConnectionFactory and com.ibm.msg.client.jms.JmsDestination.

I tried adding websphere 7 runtime and also a few jars that i read in other forums. Nothing is happening

Any ideas please

来源:https://stackoverflow.com/questions/29202105/compilation-error-in-rad-8-5-jms-message-producer-client-to-post-message-to-we

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!