Java JMS客户端应用程序需要哪一组jar才能发布消息。 我的课程路径上有 activemq-client-5.13.3.jar 。但是还不够,而且越来越
'Exception in thread "main" java.lang.NoClassDefFoundError:
javax/management/j2ee/statistics/Stats'.
注意:-在添加'activemq-all' jar时。它将正常工作,但是我不想添加这些多个jar,因为它大约为17MB。
Connection connection = null;
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("customerTopic");
connection.start();
String payload = "Important task";
Message msg = session.createTextMessage(payload);
MessageProducer producer = session.createProducer(topic);
producer.send(msg);
Thread.sleep(3000);
session.close();
if(connection != null) {
connection.close();
}
}
答案 0 :(得分:2)
一种简单的查找方法是将maven与ActiveMQ source code一起从git中检出。移至activemq-client项目文件夹,并要求Maven生成依赖关系树mvn dependency:tree
[INFO] org.apache.activemq:activemq-client:bundle:5.15.10-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO] +- org.fusesource.hawtbuf:hawtbuf:jar:1.11:compile
[INFO] +- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:compile
[INFO] +- commons-net:commons-net:jar:3.6:compile
[INFO] +- javax.jmdns:jmdns:jar:3.4.1:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.25:test
[INFO] \- log4j:log4j:jar:1.2.17:runtime
在您的情况下,您可以切换到5.13.3的发行版标签以获取确切的列表,尽管我认为自该发行版以来它并没有太大变化。当然,如果您使用maven构建项目,那么也可以从项目目录中进行操作,它会为您提供整个项目的依赖树。