Tutorial: Starting with Glassfish and JMS

Remark 11.12.2010:
I seriously tried to make this running using Glassfish V3. Several hours in poking around with the various libraries, it just does not work. If ever someone comes around who found the solution, let us know !
Related posts: http://stackoverflow.com/questions/4311157/glassfish-v3-x-and-remote-standalone-client and http://www.java.net/forum/topic/glassfish/glassfish/class-and-libraries-jms-client-and-gf-3x

Remark 08.11.2010:
This is a very popular blog entry ! But it is from January 2009 and refers to Glassfish V2. The below tutorial does not work with Glassfish V3. I am currently reviewing it and creating an updated walk-through with the latest version(s). Stay tuned.

Remark 21.07.2011:
To all JMS fans, please consider ActiveMQ as alternative. I documented all necessary steps here (javadude.wordpress.com/2011/07/21/glassfish-v3-1-running-embedded-activemq-for-jms-part-1)
I gave up on Glassfish JMS (at least for external apps).

Despite tons of material, downloads and websites on JAVA enterprise applications, tools and features, there are few sources only for “Let’s get started” styled tutorials. The Netbeans tutorial is often the best starting point (link).

I was reading about the background of JMS, some of the material is of a very theoretical nature and I tried to find some simple sample to get my hands dirty. A good short article on JMS in the glassfish context you can find at java.net (link)

This tutorial describes the steps to get a most simple messaging application up and running implementing a one-to-many communication using topics, also called publish-subscribe. A enterprise client creates a message put it on a topic and a message-driven bean (MDB) retrieves the message.

Using: Netbeans 6.5 with installed Glassfish V2.

1. Creating a new JAVA EE project.

MyJMS Project

MyJMS Project: New Project

2. We call it MyJMS. Disable the web-application and enable application-client

My

MyJMS Project: New EE Application

3. We will have a project window with 2 subprojects for the EJB and the application client.

d

MyJMS Project

4. Before we start with the coding of the EJB and the client, we configure the applicationserver. Open the admin console via right click on the application server under services (Start the server first, if not done yet). You remember the default admin password for glassfish ? “adminadmin”.You better change if your box is open to outside world.

tut09010003_

MyJMS: View Admin Console

In the admin console we create the ressources for the JMS topic.

tut09010006_

MyJMS: Add Resources

Create a destination resource with JNDI name “jms/topic” and Resource type “javax.jms.topic” (rest default settings).
Create a connection factory with the JNDI name “jms/TopicFactory” (rest default settings, but remove username and password).

5. Now we take care of the application client who will send a message to the topic destination.
The IDE created a main.java template for us.

tut09010005_

MyJMS: main.java template

Resource injection by adding these 4 lines

@Resource(mappedName=”jms/TopicFactory”)
private static ConnectionFactory topicFactory;

@Resource(mappedName=”jms/Topic”)
private static Topic topic;

tut09010007_

MyJMS: Resource Injection

Adding code to create a connection an send message

Connection topicConnection = null;
Session session = null;
MapMessage message = null;
MessageProducer producer = null;

try {
topicConnection = topicFactory.createConnection();
session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(topic);
message = session.createMapMessage();

message.setString(“lastname”, “Smith”);
message.setString(“firstname”, “John”);
message.setString(“id”, “0100″);

producer.send(message);
}
catch (Exception e) {…

tut09010011_

MyJMS: Send a message

6. Now we create a message-driven bean that consumes the message. Let’s call it MessageBean

Create new messagedriven bean

MyJMS: Create new message-driven bean

tut09010005_new_message-driven_bean

MyJMS: New message-driven bean

We create it in the package ejb and connect it to the server destination we created earlier. Netbeans creates a basic template for us.

tut09010010_

MyJMS: MDB Skeleton

We need to inject the resources again:

@Resource(mappedName=”jms/TopicFactory”)
private ConnectionFactory topicFactory;
@Resource(mappedName=”jms/Topic”)
private Topic topic;

And we add some code to onMessage method:

MapMessage msg = null;
try {

msg = (MapMessage)message;
System.out.println(“—————————————-”);
System.out.println(msg.getString(“lastname”));
System.out.println(msg.getString(“firstname”));
System.out.println(msg.getString(“id”));
System.out.println(“—————————————-”);
}
catch (Exception e) {…

Read the message

MyJMS: Read the message

7. Lets run it:

Glassfish Log:

—————————————-
Smith
John
0100
—————————————-

Conclusion: This is the most basic version of a messaging application. Please note there is no proper error handling or any business logic or whatsoever. There is no documentation in the above code because some of the abstract commands are so sophisticated that the tutorial would become a compendium and you are back to square one: It is too much to swallow.

My recommendation:
Get something simple up and running and then start tweaking and start to understand.

Potential Problems:

  • You might hit a cast error when trying to receive the message. Change the JMS settings from EMBEDDED to LOCAL. Dont ask me why.
    DirectConsumer:Caught Exception delivering messagecom.sun.messaging.jmq.io.Packet cannot be cast to com.sun.messaging.jms.ra.DirectPacket

    tut09010001_

    Glassfish Configuration: JMS settings

About these ads

25 thoughts on “Tutorial: Starting with Glassfish and JMS

  1. Thanks alot for this simple example.
    But when I run the client I get a NullPointerException on the line:
    topicConnection = topicFactory.createConnection();

    looks like the ConnectionFactory isn’t being injected. Any idea why and how to fix it?

    BTW I used the same example (after changing it a little) to create a MDB for a queue.

  2. This is a great sample…

    But, like Rawl, I get the same NullPointerException.

    Is there a fix for this?

    Thanks!

  3. Thank for this example, after reading documentation about JMS and MDB i have been searching for a simple sample to apply whatever i read, finally i got this tutorial, which is simple , but covers most of the aspects of JMS, this sample is working well for me,

  4. To avoid confusion

    While creating the destination resource with JNDI name “jms/topic” and Resource type “javax.jms.topic” (rest default settings).

    JNDI name should be jms/Topic. (‘T’ not ‘t’) :)
    My glassfish v2 asked for a ‘Physical Destination Name’. Give some junk value or you can first add a physical destination under admin console->configuration->Java Message Service->Physical Destinations->New (“somename” as name, “javax.jms.Topic” as Type) and then specify the newly added physical destination name.

    While creating a connection factory with the JNDI name “jms/TopicFactory” (rest default settings, but remove username and password) specify the type as “javax.jms.TopicConnectionFactory”

    Regards,
    Rubic INDIA

  5. HI All:

    Good tutorial, except I can’t get it to work. I am running NetBean 6.8.1M on Ubuntu 9.04 . Glassfish v3 prelude. When I try to setup the Destination Resource with the following values, I get this error on the glassfish admin console.
    JNDI Name: jms/Topic
    Physical Destination Name : “somename”
    Resource Type: javax.jms.Topic
    Status: Enabled

    Then I get this error once I press the OK button to create the resource.

    An error has occurred.
    org.hibernate.ejb.HibernatePersistence.isLoadedWithoutReference(Ljava/lang/Object;Ljava/lang/String;)Ljavax/persistence/spi/LoadState;

  6. The error message above ie “Hibernate” error on Netbean Admin Console was coming from glassfish V3 Prelude.

    I change to glassfish V2 latest built and things work as they are supposed to.

    Thanks again for the above example.

  7. Well written tutorial, but I still can’t get it to work…
    I’m getting CONNECTION REFUSED all over the place, and it seems like it wants to connect to port 3700 for some reason even though JMS appears to be running on 7676. Any ideas?

  8. Never mind! Got it fixed, had to go into domain.xml and sun-acc.xml and fix my domain name. I had changed the domain name of my machine since my last install of GlassFish v2-ur1.

    Thanks for the nice tutorial!!

  9. Excellent example, but does not work. I have the following error:

    “DPL8007: Elemento message-destination y valor null de descriptores de implementación no válidos”
    endpoint.determine.destinationtype
    MQJMSRA_DC2001: connectionId=8999358329247142656:_setClientID():JMSService.setClientId():JMSServiceException=setClientId: set client ID failed. Connection ID: 8999358329247142656, Client ID: MessageBean, Shareable: false, nameSpace: null
    createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to
    javax.resource.NotSupportedException: MQRA:EC:Error creating Direct Message Consumer:
    createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:966)
    at com.sun.messaging.jms.ra.EndpointConsumer._init(EndpointConsumer.java:305)
    at com.sun.messaging.jms.ra.EndpointConsumer.(EndpointConsumer.java:215)
    at com.sun.messaging.jms.ra.ResourceAdapter.endpointActivation(ResourceAdapter.java:604)
    at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:256)
    at com.sun.ejb.containers.MessageBeanContainer.(MessageBeanContainer.java:209)
    at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:524)
    at com.sun.enterprise.server.AbstractLoader.loadEjbs(AbstractLoader.java:527)
    at com.sun.enterprise.server.ApplicationLoader.doLoad(ApplicationLoader.java:191)
    at com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLoader.java:126)
    at com.sun.enterprise.server.ExtendedApplicationLoader.doLoad(ExtendedApplicationLoader.java:134)
    at com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:238)
    at com.sun.enterprise.server.AbstractManager.load(AbstractManager.java:226)
    at com.sun.enterprise.server.ApplicationLifecycle.onStartup(ApplicationLifecycle.java:224)
    at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:446)
    at com.sun.enterprise.server.ondemand.OnDemandServer.onStartup(OnDemandServer.java:134)
    at com.sun.enterprise.server.PEMain.run(PEMain.java:409)
    at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)
    Caused by: javax.jms.JMSException: createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1645)
    at com.sun.messaging.jms.ra.DirectSession.createDurableSubscriber(DirectSession.java:354)
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:944)
    … 22 more
    Caused by: com.sun.messaging.jmq.jmsservice.JMSServiceException: addConsumer: Add consumer failed. Connection ID: 8999358329247142656, session ID: 8999358329247146496
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1320)
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1595)
    … 24 more
    Caused by: java.lang.NullPointerException
    at com.sun.messaging.jmq.jmsserver.core.Subscription.calcHashcode(Subscription.java:260)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.(Subscription.java:287)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:887)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:854)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:975)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:931)
    at com.sun.messaging.jmq.jmsserver.data.handlers.ConsumerHandler.createConsumer(ConsumerHandler.java:639)
    at com.sun.messaging.jmq.jmsserver.data.protocol.ProtocolImpl.createConsumer(ProtocolImpl.java:479)
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1303)
    … 25 more
    MDB00017: [MessageBean]: Se produjo una excepción al crear el contenedor de Bean controlado por mensajes: [java.lang.Exception]
    java.lang.Exception
    java.lang.Exception
    at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:265)
    at com.sun.ejb.containers.MessageBeanContainer.(MessageBeanContainer.java:209)
    at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:524)
    at com.sun.enterprise.server.AbstractLoader.loadEjbs(AbstractLoader.java:527)
    at com.sun.enterprise.server.ApplicationLoader.doLoad(ApplicationLoader.java:191)
    at com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLoader.java:126)
    at com.sun.enterprise.server.ExtendedApplicationLoader.doLoad(ExtendedApplicationLoader.java:134)
    at com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:238)
    at com.sun.enterprise.server.AbstractManager.load(AbstractManager.java:226)
    at com.sun.enterprise.server.ApplicationLifecycle.onStartup(ApplicationLifecycle.java:224)
    at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:446)
    at com.sun.enterprise.server.ondemand.OnDemandServer.onStartup(OnDemandServer.java:134)
    at com.sun.enterprise.server.PEMain.run(PEMain.java:409)
    at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)
    Caused by: javax.resource.NotSupportedException: MQRA:EC:Error creating Direct Message Consumer:
    createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:966)
    at com.sun.messaging.jms.ra.EndpointConsumer._init(EndpointConsumer.java:305)
    at com.sun.messaging.jms.ra.EndpointConsumer.(EndpointConsumer.java:215)
    at com.sun.messaging.jms.ra.ResourceAdapter.endpointActivation(ResourceAdapter.java:604)
    at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:256)
    … 18 more
    Caused by: javax.jms.JMSException: createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1645)
    at com.sun.messaging.jms.ra.DirectSession.createDurableSubscriber(DirectSession.java:354)
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:944)
    … 22 more
    Caused by: com.sun.messaging.jmq.jmsservice.JMSServiceException: addConsumer: Add consumer failed. Connection ID: 8999358329247142656, session ID: 8999358329247146496
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1320)
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1595)
    … 24 more
    Caused by: java.lang.NullPointerException
    at com.sun.messaging.jmq.jmsserver.core.Subscription.calcHashcode(Subscription.java:260)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.(Subscription.java:287)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:887)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:854)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:975)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:931)
    at com.sun.messaging.jmq.jmsserver.data.handlers.ConsumerHandler.createConsumer(ConsumerHandler.java:639)
    at com.sun.messaging.jmq.jmsserver.data.protocol.ProtocolImpl.createConsumer(ProtocolImpl.java:479)
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1303)
    … 25 more
    EJB5090: Se produjo una excepción al crear el contenedor EJB [java.lang.Exception]
    appId=MyJMS moduleName=MyJMS-ejb_jar ejbName=MessageBean
    LDR5004: Se produjo un error inesperado al crear el contenedor ejb
    java.lang.Exception
    at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:265)
    at com.sun.ejb.containers.MessageBeanContainer.(MessageBeanContainer.java:209)
    at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:524)
    at com.sun.enterprise.server.AbstractLoader.loadEjbs(AbstractLoader.java:527)
    at com.sun.enterprise.server.ApplicationLoader.doLoad(ApplicationLoader.java:191)
    at com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLoader.java:126)
    at com.sun.enterprise.server.ExtendedApplicationLoader.doLoad(ExtendedApplicationLoader.java:134)
    at com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:238)
    at com.sun.enterprise.server.AbstractManager.load(AbstractManager.java:226)
    at com.sun.enterprise.server.ApplicationLifecycle.onStartup(ApplicationLifecycle.java:224)
    at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:446)
    at com.sun.enterprise.server.ondemand.OnDemandServer.onStartup(OnDemandServer.java:134)
    at com.sun.enterprise.server.PEMain.run(PEMain.java:409)
    at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)
    Caused by: javax.resource.NotSupportedException: MQRA:EC:Error creating Direct Message Consumer:
    createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:966)
    at com.sun.messaging.jms.ra.EndpointConsumer._init(EndpointConsumer.java:305)
    at com.sun.messaging.jms.ra.EndpointConsumer.(EndpointConsumer.java:215)
    at com.sun.messaging.jms.ra.ResourceAdapter.endpointActivation(ResourceAdapter.java:604)
    at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:256)
    … 18 more
    Caused by: javax.jms.JMSException: createConsumer on JMSService:jmsdirect failed for connectionId:8999358329247142656 and sessionId:8999358329247146496 due to unkown JMSService server error.
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1645)
    at com.sun.messaging.jms.ra.DirectSession.createDurableSubscriber(DirectSession.java:354)
    at com.sun.messaging.jms.ra.EndpointConsumer.createDirectMessageConsumer(EndpointConsumer.java:944)
    … 22 more
    Caused by: com.sun.messaging.jmq.jmsservice.JMSServiceException: addConsumer: Add consumer failed. Connection ID: 8999358329247142656, session ID: 8999358329247146496
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1320)
    at com.sun.messaging.jms.ra.DirectSession._createAndAddConsumer(DirectSession.java:1595)
    … 24 more
    Caused by: java.lang.NullPointerException
    at com.sun.messaging.jmq.jmsserver.core.Subscription.calcHashcode(Subscription.java:260)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.(Subscription.java:287)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:887)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.subscribe(Subscription.java:854)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:975)
    at com.sun.messaging.jmq.jmsserver.core.Subscription.findCreateDurableSubscription(Subscription.java:931)
    at com.sun.messaging.jmq.jmsserver.data.handlers.ConsumerHandler.createConsumer(ConsumerHandler.java:639)
    at com.sun.messaging.jmq.jmsserver.data.protocol.ProtocolImpl.createConsumer(ProtocolImpl.java:479)
    at com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.addConsumer(IMQDirectService.java:1303)
    … 25 more
    Error al intentar procesar las extensiones del Manifest del archivo JAR C:\Users\Jessica\.personalDomain\personalDomain\applications\j2ee-apps\MyJMS\MyJMS-ejb.jar; se ignorará y se continuará
    java.io.FileNotFoundException: C:\Users\Jessica\.personalDomain\personalDomain\applications\j2ee-apps\MyJMS\MyJMS-ejb.jar (El sistema no puede encontrar el archivo especificado)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.(ZipFile.java:114)
    at java.util.jar.JarFile.(JarFile.java:133)
    at java.util.jar.JarFile.(JarFile.java:97)
    at com.sun.enterprise.appclient.jws.ExtensionFileManager.findExtensionTransitiveClosure(ExtensionFileManager.java:240)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportInfo.findExtensions(AppclientJWSSupportInfo.java:1545)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportInfo.prepareAppclient(AppclientJWSSupportInfo.java:1386)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportInfo.prepareNestedAppclient(AppclientJWSSupportInfo.java:1497)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportInfo.prepareApplication(AppclientJWSSupportInfo.java:1246)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportInfo.startJWSServicesForApplication(AppclientJWSSupportInfo.java:475)
    at com.sun.enterprise.appclient.jws.AppclientJWSSupportManager.handleApplicationEvent(AppclientJWSSupportManager.java:156)
    at com.sun.enterprise.server.event.ApplicationLoaderEventNotifier.notifyListeners(ApplicationLoaderEventNotifier.java:154)
    at com.sun.enterprise.server.AbstractLoader.notifyAppEvent(AbstractLoader.java:874)
    at com.sun.enterprise.server.ApplicationLoader.doLoad(ApplicationLoader.java:192)
    at com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLoader.java:126)
    at com.sun.enterprise.server.ExtendedApplicationLoader.doLoad(ExtendedApplicationLoader.java:134)
    at com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:238)
    at com.sun.enterprise.server.AbstractManager.load(AbstractManager.java:226)
    at com.sun.enterprise.server.ApplicationLifecycle.onStartup(ApplicationLifecycle.java:224)
    at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:446)
    at com.sun.enterprise.server.ondemand.OnDemandServer.onStartup(OnDemandServer.java:134)
    at com.sun.enterprise.server.PEMain.run(PEMain.java:409)
    at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)

  10. The Concept of this Sample is Awesome…

    Unfortunately, two hours into my first attempt…using:
    Netbeans 6.8, Glassfish v3.

    Is it safe to assume this only installs smoothly using:
    Netbeans 6.5 with installed Glassfish V2.

    And any newer version will ironically require the in-depth theoretical knowledge the author was trying to avoid…

  11. Hello,

    Can you please let me know the fix for this, if any.

    This is my beginning tutorial on JMS and will be helpful if I can get this to work.

    Thanks.

    Copying 4 files to C:\projects\NetBeansProjects\MyJMS\dist\MyJMSClient
    Letting agent QTJA do the transformation
    java.lang.NullPointerException
    at org.glassfish.appclient.client.acc.ACCLogger$1.run(ACCLogger.java:149)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.glassfish.appclient.client.acc.ACCLogger.reviseLogger(ACCLogger.java:146)
    at org.glassfish.appclient.client.acc.ACCLogger.init(ACCLogger.java:93)
    at org.glassfish.appclient.client.acc.ACCLogger.(ACCLogger.java:80)
    at org.glassfish.appclient.client.AppClientFacade.createBuilder(AppClientFacade.java:360)
    at org.glassfish.appclient.client.AppClientFacade.prepareACC(AppClientFacade.java:247)
    at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.premain(AppClientContainerAgent.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)

  12. this code will obviously not work, since no container will intercept class Main and inject the necessary annotated @Resources. It needs to be a managed bean, ejb, servlet (sometimes depending upon the container) and so on to work with ejb 3.0 injection. For the client you will need to lookup your dependencies through JNDI.

  13. hey guys, i need help on this

    LDR5004: UnExpected error occured while creating ejb container
    CORE5021: Application NOT loaded: [MyJMS]
    ADM1075:Error on listening event:[Error while loading application [MyJMS]. Please refer to the server log for more details. ]

    it is not working :’(

  14. Question: How to make this work with Netbean 6.9.1 with Glassfish 3.0.1? Any help will be appreciated. Here are errors I got–
    —————————————————————————————
    com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Res-Ref-Env-Property: myjms.Main/topicFactory@javax.jms.ConnectionFactory@ resolved as: jndi: jms/TopicFactory@res principal: null@mail: null
    No Runtime properties
    Database Vendor : null
    Create Tables at Deploy : false
    Delete Tables at Undeploy : false into class myjms.Main
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:614)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:384)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:210)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:202)
    at org.glassfish.appclient.client.acc.AppClientContainer$ClientMainClassSetting.getClientMainClass(AppClientContainer.java:599)
    at org.glassfish.appclient.client.acc.AppClientContainer.getMainMethod(AppClientContainer.java:498)
    at org.glassfish.appclient.client.acc.AppClientContainer.completePreparation(AppClientContainer.java:397)
    at org.glassfish.appclient.client.acc.AppClientContainer.prepare(AppClientContainer.java:311)
    at org.glassfish.appclient.client.AppClientFacade.prepareACC(AppClientFacade.java:264)
    at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.premain(AppClientContainerAgent.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
    Caused by: javax.naming.NamingException: Lookup failed for ‘java:comp/env/myjms.Main/topicFactory’ in SerialContext targetHost=localhost,targetPort=3700,orb’sInitialHost=localhost,orb’sInitialPort=3700 [Root exception is javax.naming.NamingException: Lookup failed for ‘jms/TopicFactory’ in SerialContext targetHost=localhost,targetPort=3700,orb’sInitialHost=localhost,orb’sInitialPort=3700 [Root exception is javax.naming.NameNotFoundException: TopicFactory not found]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:513)
    … 15 more
    Caused by: javax.naming.NamingException: Lookup failed for ‘jms/TopicFactory’ in SerialContext targetHost=localhost,targetPort=3700,orb’sInitialHost=localhost,orb’sInitialPort=3700 [Root exception is javax.naming.NameNotFoundException: TopicFactory not found]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:87)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:688)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:657)
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:148)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:428)
    … 17 more
    Caused by: javax.naming.NameNotFoundException: TopicFactory not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:197)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:168)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)
    at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:89)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
    Java Result: 1
    ——————————————————-

  15. Sr but i had this error “The module has not been deployed” and i’v already change from EMBEDDED to LOCAL
    . please help , i’m newbie so any advice will be a great help . thanks for you time

  16. code as given works with NB 7.01 and GF 3.1
    getting this error “com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Res-Ref-Env-Property: myjms.Main/topicFactory@javax.jms.ConnectionFactory@ resolved as: jndi: jms/TopicFactory@res principal: null@mail: null” –> check if type and Name of ConnectionFactory is correctly created via Admin Console of GF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s