简体   繁体   中英

Cant init context with JMS

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM