aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Unable to run Java SE Client that Sends Messages to a JMS Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Unable to run Java SE Client that Sends Messages to a JMS Queue" Watch "Unable to run Java SE Client that Sends Messages to a JMS Queue" New topic
Author

Unable to run Java SE Client that Sends Messages to a JMS Queue

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Source:9.2. Creating a Java SE Client that Sends Messages to a JMS Queue
OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012


As stated in the example,one has to:

If using GlassFish v3, include the appropriate runtime library JAR on the classpath: $GLASSFISH_HOME/modules/gf-client.jar

The location on my system was:
C:\glassfish3\glassfish\lib\gf-client.jar


I added the jar to Lib folder of MessageDrivenBeanSEClient Java Project and then I right-clicked on the jar from the lib folder in eclipse and selected Build Path-->Add to Build Path.
Then I refreshed the Project But still I see the following errors in the MessageDrivenBeanSEClient:

The import javax.jms cannot be resolved


Please advise How to resolve this issue .


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1661
    
  25

Hi Mohit,

It seems you don't have the JMS libraries on your classpath.

Do the following on your client-project: Right-mouse-click - Properties - Java Build Path - select Tab "Libraries" - Add Library - Server Runtime - select Glassfish - click Finish - click OK.

Regards,
Frits
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Hi Frits,

Thanks for the advise.
The Previous issue is resolved.However ,Now I am seeing the following exception on running MessageDrivenBeanSEClient :


Below is the code for "MessageDrivenBeanSEClient".Also,QueueMessageDrivenBeanExample is up and running:


Please advise.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1661
    
  25

How did you define the "jms/QueueConnectionFactory" and "jms/QueueDestination"?

You can verify if they are there and they are well defined ( I am assuming that you are using glassfish ) by starting the admin-console (start-up the server, then right-click the server -> Glassfish -> View Admin Console.

After starting-up the admin-console check the
Resources -> JMS Resources -> Connection Factories
Resources -> JMS Resources -> Destination

If they are not there click the New... button and define them under the names you use in your lookup: "jms/QueueConnectionFactory" and "jms/QueueDestination".

Regards,
Frits
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

"jms/QueueConnectionFactory" and "jms/QueueDestination" are already defined in Glass-Fish Server.
Attached screenshots.



[Thumbnail for Queue_Connection_Factory.JPG]


[Thumbnail for Queue_Destination.JPG]

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1661
    
  25

"jms/QueueConnectionFactory" and "jms/QueueDestination" are already defined in Glass-Fish Server.

Hmm strange, I just tried the example and I also run into problems (on the Queue, but not on the QueueConnectionFactory)....

Regards,
Frits
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

I am still facing the issue on the same line of code:

Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 84
Mohit,

Can you please try the following

  • Write A session bean and look up the connectionFactory from session bean (basically whatever you are doing in your Java SE Client)
  • deploy the session bean
  • Invoke the session bean from standalone client


  • If the above works , that will ensure that your server configuration of connection factory and queues is correct.

    Something must be wrong in your MDB client , other people who have experienced similiar problems , they fixed it by modifying the classpath.
    you need to make sure that you are referring the glassfish-client jar directly from installation directory (not from some other location on your system) because it contains MF file which includes the other liberaries automatically. see below link. Hope this will help you.

    http://www.coderanch.com/t/475014/java/java/JNDI-initial-context-lookup-problems


    SCJP 5.0 94%
    OCE-EJBD 90%
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Hi Ravi,

    Write A session bean and look up the connectionFactory from session bean (basically whatever you are doing in your Java SE Client)
    deploy the session bean
    Invoke the session bean from standalone client


    The above steps worked and I was able to see the following line in server.logs

    JMS Resource Loopup Finished.

    However,I am still not able to understand what's wrong in the MDB SE client.
    I had added the following jar's manually to Lib folder of MessageDrivenBeanSEClient Java Project and then I right-clicked on the jar from the lib folder in eclipse and selected Build Path-->Add to Build Path.
    Then I refreshed the Project

    gf-client.jar (Path:C:\glassfish3\glassfish\lib)
    appserv-rt.jar (Path:C:\glassfish3\glassfish\lib)


    Please advise.
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1661
        
      25

    Hi Mohit,

    I got it working and don't ask me why but the problem in my case was that I had defined the "Physical Destination Name" the same as the JNDI name.

    When I changed that name in the "JMS Destination Resource" properties, it worked:


    25-feb-2013 20:21:54 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
    INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
    *** Starting JMS Resource Lookup...
    25-feb-2013 20:21:58 org.hibernate.validator.internal.util.Version <clinit>
    INFO: HV000001: Hibernate Validator 4.3.0.Final
    25-feb-2013 20:21:58 com.sun.messaging.jms.ra.ResourceAdapter start
    INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter: Version: 4.5.2 Patch 1 (Build 3-d) Compile: Thu Jun 7 10:46:15 PDT 2012
    25-feb-2013 20:21:58 com.sun.messaging.jms.ra.ResourceAdapter start
    INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter starting: broker is REMOTE, connection mode is TCP
    25-feb-2013 20:21:58 com.sun.messaging.jms.ra.ResourceAdapter start
    INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter Started:REMOTE
    JMS Resource Loopup Finished.
    ### Sent message: 1
    ### Sent message: 2
    ### Sent message: 3
    ### Sent message: 4
    ### Sent message: 5
    ### Sent message: 6
    ### Sent message: 7
    ### Sent message: 8
    ### Sent message: 9
    ### Sent message: 10
    *** Java SE JMS Client finished.


    Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Even after many tries,its still not working for me.
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1661
        
      25

    Hi Mohit,

    I would just leave it if I were you.

    It has to do with configuration items, not with your coding. (if you are really eager to get it working, try Jboss or another Application Server)

    Regards,
    Frits
    gurpeet singh
    Ranch Hand

    Joined: Apr 04, 2012
    Posts: 924
        
        1

    in this example is the client a standalone java client or an application client ? because if it is a standalone client i couldnt see any jndi properties being passed to InitialContext constructor like URL or protocol to be used to connect to remote glassfish server
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1661
        
      25

    in this example is the client a standalone java client or an application client ? because if it is a standalone client i couldnt see any jndi properties

    It is a standalone client, and you don't have to pass any properties when getting the initial context (I guess that the connection is handled now by the gf-client.jar)

    Regards,
    Frits
    Vipul Kumar
    Greenhorn

    Joined: Jun 27, 2012
    Posts: 4
    Mohit G Gupta wrote:"jms/QueueConnectionFactory" and "jms/QueueDestination" are already defined in Glass-Fish Server.
    Attached screenshots.


    Check the Physical Destination Name of your JNDI resources. Make sure they don't contain any special characters (not even "/"). I doubt you must have named them like: "jms/QueueDes.tination" just like your JNDI names.
    Physical Destination Name doesn't accepts special characters (slashes - /). I had the same problem.
    Good Luck
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Unable to run Java SE Client that Sends Messages to a JMS Queue