title: JMS and ActiveMQ exception
body: <p>I'm trying a project for school using JMS and ActiveMQ.</p>
  
  <p>I copied the block of code from O'Reilly's books "Java Message Service 2nd Edition Jun 2009". It uses the publish and subscribe method and is in fact a small chat where everyone connected to the topic can send messages to everyone and everyone can see everyone else's messages. I compile the program and everything is ok, i try to run it and it gives me the following exception:</p>
  
  <pre><code>Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.activemq.jndi.ActiveMQInitialContextFactory]
  </code></pre>
  
  <p>I found that this problem might be because of 2 reasons: </p>
  
  <ol>
  <li>activemq-all-5.2.0.jar is not added to classpath.<br>
  BUT added it the classpath (EnvironmentVariables->select ClassPath->Edit  and add the following: "D:\Programming\JMS\ActiveMQ\apache-activemq-5.2.0" (THIS IS HOW YOU ADD IT NO?!?!)</li>
  <li><p>jndi.properties file is not defined properly or has not been added to the classpath.<br>
  BUT i CREATED IT and added it's folder to the classpath. Here is what it contains:</p>
  
  <pre><code>java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
  java.naming.provider.url = tcp://localhost:61616
  java.naming.security.principal=system
  java.naming.security.credentials=manager
  connectionFactoryNames = TopicCF
  topic.topic1 = jms.topic1
  </code></pre></li>
  </ol>
  
  <p>What is the problem? I have tried for ages to make it work. Am i doing something wrong? :(</p>
  
  <p>Does the jndi.properties file path matter? or it only has to be placed in classpath and from here it can be found?</p>
  
  <p>I also ran the activemq.bat from the bin folder D:\Programming\JMS\ActiveMQ\apache-activemq-5.2.0\bin\</p>
  
  <p>[Edit]---------------------
  So it works in Eclipse, BUT
  Now i've properly added the .jar file in environment variables and i've run the client from windows's cmd. It doesn't give any errors, when i write in Eclipse's console, it appears in cmd console, everything ok, but when i try to write in cmd it gives an error at this line:</p>
  
  <pre><code>publisher.publish(message);
  </code></pre>
  
  <p>and it says </p>
  
  <pre><code>java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQMessageProducerSupport.getDestination()Ljavax/jms/Destination;
  </code></pre>
  
  <p>Any ideas? I'd really like to be able to run it in CMD. :(</p>
  
  <p>---------------------[/Edit]</p>