1

i have problems with setting up JMS. I tried using Active MQ and OpenJMS but the same error occurs. Iam clueless on how to solve it:

When i execute this:

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;

public class Main {
    public static void main(String[] args) throws NamingException {
        Hashtable properties = new Hashtable();

        properties.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.exolab.jms.jndi.InitialContextFactory");
        properties.put(Context.PROVIDER_URL, "tcp://localhost:3035/");

        Context context = new InitialContext(properties);
    }
}

I get this error:

Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.exolab.jms.jndi.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.exolab.jms.jndi.InitialContextFactory]

After some googling i think the problem is that a jar is not in the right classpath, but all the answers already assume that i know which jar and where to store it, but this is not the case here.

Which Jar are they talking about? Where can i get it? Where do i need to store it?

Iam using IntelliJ btw. Could you point me in the right direction?

ActiveMQ is working (http://localhost:8161/ shows webpage of ActiveMQ)

Here are my steps on how i created the project: File -> New Project -> Java -> SDK1.8 -> Next -> Next -> Project Name: Test -> Right click src folder -> New -> Java Class -> Name: Main -> Paste code from above -> Run -> Error

EDIT: for all the people having the same errors: OpenJMS comes with a libfolder. Install these libraries and it should work

Loading
  • 1,098
  • 1
  • 12
  • 25

1 Answers1

0

Here is a good explanation on how to add external jars to your project in intellij, and regarding to

Which Jar are they talking about? Where can i get it?

here is a useful web site where you can search jar files using criterias as the name of a class or a package.

I think the jar you are needing is Openjms, here is a link to download it.

David Florez
  • 1,460
  • 2
  • 13
  • 26
  • thank you for your answer. I had to install 3 missing classes. Now a different problem arises. I really dont know if its really that hard to get JMS working, or iam just doing it wrong. This is now the error: Exception in thread "main" javax.naming.NamingException: Failed to connect to JNDI provider [Root exception is java.net.ConnectException: Connection refused: connect] – Loading Jun 06 '17 at 20:23
  • @Loading in your code try changing `"tcp://localhost:3035/"` for `"tcp://localhost:61616/"` which is the default address of ActiveMQ or since you are using the OpenJMS client, try using the OpenJMS server instead of the ActiveMQ's one – David Florez Jun 06 '17 at 20:49
  • big thank you. I just totally installed the wrong jars. When downloading openJMs they provide you with a folder call libs. Didnt know i had to use these. – Loading Jun 08 '17 at 19:40
  • @Loading glad to hear that you could make it work, if there isn't any other problem please mark the question as solved – David Florez Jun 08 '17 at 19:45