public class JMSSender {   
    /**  
     * @param args  
     * @throws NamingException   
     * @throws JMSException   
     */  
    public static void main(String[] args) throws NamingException, JMSException {   
        //init JNDI context   
       String JNDIFactory = "weblogic.jndi.WLInitialContextFactory";//define JNDI context factory   
        String providerUrl = "t3://localhost:7001"; //define weblogic JMS url   
        Hashtable env = new Hashtable();   
        env.put(Context.INITIAL_CONTEXT_FACTORY, JNDIFactory);   
        env.put(Context.PROVIDER_URL, providerUrl);   
        Context ctx = new InitialContext(env);   
           
        //find connection factory  
       String connFactoryJNDI = "JMSConnectionFactory"; //jms connectionFactory JNDI name   
        QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(connFactoryJNDI);   
        //create queue connection   
        QueueConnection qConn = (QueueConnection) connFactory.createConnection();   
        //create session   
        QueueSession qSession = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);   
        //find queue by JNDI lookup   
        Queue queue = (Queue) ctx.lookup("SAFQueue-in");  //RequestQueue  (SAFQueue-in)
        //create sender   
        QueueSender qSender = qSession.createSender(queue);   
        //create message   
        Message msg = qSession.createTextMessage("Message is from JMS Sender!saf");   
        qSender.send(msg);   
           
        qSender.close();   
           
       qSession.close();   
           
        qConn.close();   
         
        System.out.println("发送消息完毕!");   
    }