Java EE – what Maven dependencies can I use to create a separate JMS client for GlassFish?
I want to create a very simple JMS standalone client for JMS topics hosted on my GlassFish server
My project was built using Maven
I know there seems to be some confusion when using JMS dependencies, so what dependencies do I use in my POM
>Connect to my JNDI context @ h_ 404_ 7 @ > can you read my JMS topic?
My java test method is
/** 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); } }
My POM currently contains the following dependencies
<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>
Solution
OK, this is tricky
After some searching and trying, I deleted the welding dependency (to get back to the more classic main)
Then I replaced it with my (old-fashioned) appserv-rt.jar
<dependency> <groupId>org.glassfish.appclient</groupId> <artifactId>gf-client</artifactId> <version>3.1</version> <type>pom</type> <scope>compile</scope> </dependency>
This doesn't change much, because GF client provides all the jars for GlassFish, which will obviously produce a lot of jars (we hope to have 7000 to optimize the number of jars, although we all know that it is optimized too early)
Therefore, once completed, you can use the EJB remote interface, but you can't use JMS (for incomprehensible reasons) In order for JMS to work with GF client, it must be imqjmsra Jar and imqbroker Jar creates Maven dependencies, both in% glassfish3_ INSTALL_ Dir% / GlassFish / lib / install / applications / jmsra In addition, due to imqjmsra Imqbroker.jar is used internally Jar, I suggest you create the following 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>
And imqjmsra Jar associated with @ h_ 404_ 7 @ and
<?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>
With imqbroker Jar
Obviously, when I use nexus repository management, it is easier for me to use nexus "upload artifact page" to create these dependencies in our company's third-party local repository
Once completed, my POM dependency is now
<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>
I can poll my JMS queue completely