java-ee – 我可以使用哪些maven依赖项为Glassfish创建一个独立的JMS客户端?
|
我想为我的Glassfish服务器上托管的JMS主题创建一个非常简单的JMS独立客户端. 我的项目是使用maven构建的. 我知道在使用JMS依赖关系时似乎有些混乱,所以,我在我的pom中使用了哪些依赖关系 >连接到我的JNDI上下文 我的Java测试方法是 /** Thanks to WELD CDI,this method is not static */
public void main(@Observes ContainerInitialized event) throws Throwable {
Context context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory) context.lookup(JMSNotifierConstants.CONNECTION_FACTORY_NAME);
Connection connection = factory.createConnection();
Topic topic = (Topic) context.lookup(JMSNotifierConstants.NOTIFICATION_TOPIC);
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(topic);
connection.start();
while (true) {
Message received = consumer.receive();
System.out.println(received);
}
}
而我的pom目前包含以下依赖项 <dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-se</artifactId>
<version>1.0.1-Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.jms</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>appserv-rt</artifactId>
<version>3.1</version>
</dependency>
解决方法好的,这个很棘手.经过一些搜索和尝试后,我删除了焊接依赖项(为了回到更经典的主要). 然后,我用我的(旧式)appserv-rt.jar替换了 <dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
这并没有什么变化,因为gf-client为Glassfish提供了所有罐子,这显然会产生很多罐子(希望有7000来优化罐子数量,尽管我们都知道过早优化). 因此,一旦完成,完全可以使用EJB远程接口,但不能使用JMS(由于难以理解的原因).为了使JMS与gf-client一起工作,必须为imqjmsra.jar和imqbroker.jar创建maven依赖项,两者都位于%GLASSFISH3_INSTALL_DIR%/ glassfish / lib / install / applications / jmsra中.此外,由于imqjmsra.jar内部使用imqbroker.jar,我建议您创建以下poms: <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.glassfish.external.jms</groupId>
<artifactId>imqjmsra</artifactId>
<version>3.1.0</version>
<description>POM was created by Sonatype Nexus</description>
<dependencies>
<dependency>
<groupId>org.glassfish.external.jms</groupId>
<artifactId>imqbroker</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
与imqjmsra.jar相关联 <?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.glassfish.external.jms</groupId>
<artifactId>imqbroker</artifactId>
<version>3.1.0</version>
<description>POM was created by Sonatype Nexus</description>
</project>
与imqbroker.jar相关联. 显然,当我使用Nexus存储库管理时,我更容易使用Nexus“上传工件页面”在我们公司的第三方本地存储库中创建这些依赖项. 一旦完成,我的POM依赖现在就是 <dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.external.jms</groupId>
<artifactId>imqjmsra</artifactId>
<version>3.1.0</version>
</dependency>
我可以完全轮询我的JMS队列. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
