title: jms sending message on any server
body: <p>I want to write generic code for sending message on any jms server. so for that i thought if i have jndi.properties file then we can place server configuration in this file and we can access this file through the code but i am able to do this only for 'ActiveMQ Server'. Now i am facing problems to send the message on any other server like glassfish server or jboss server. can somebody help me to do this task.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>public class Producer 
  {
     public Producer() throws JMSException, NamingException,IOException 
    {
     InputStream is = getClass().getResourceAsStream("my.jndi.properties");
     Properties jndiParamaters = new Properties();
     jndiParamaters.load(is);  
     Context jndi = new InitialContext(jndiParamaters); 
     ConnectionFactory conFactory = (ConnectionFactory) jndi.lookup("connectionFactory");
     Connection connection; 
     connection = conFactory.createConnection();
  try 
  {
      connection.start();   
     Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);  
      Destination destination = (Destination) jndi.lookup("Myqueue"); 
      MessageProducer producer = session.createProducer(destination); 
      TextMessage message = session.createTextMessage("Hello World!"); 
      producer.send(message);
      System.out.println("Sent message '" + message.getText() + "'");
  } 
  finally 
  {
     connection.close();
  }
  }
  public static void main(String[] args) throws JMSException 
  {   
  try
  {
     BasicConfigurator.configure();
      new Producer();
  } 
  catch (Exception e) 
  {
    e.printStackTrace();
  }
  
  }
  
  }
  </code></pre>
  
  <p>thanks </p>