Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jms/QueueConnectionFactory" and "jms/QueueDestination" are already defined in Glass-Fish Server.
Attached screenshots.
Queue_Connection_Factory.JPG
[Thumbnail for Queue_Connection_Factory.JPG]
Connection_Factory
Queue_Destination.JPG
[Thumbnail for Queue_Destination.JPG]
Destination
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still facing the issue on the same line of code:

 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Mohit G Gupta
    Ranch Hand
    Posts: 634
    Chrome Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Saloon Keeper
    Pie
    Posts: 2536
    113
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 634
    Chrome Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Even after many tries,its still not working for me.
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Saloon Keeper
    Pie
    Posts: 2536
    113
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 924
    1
    Fedora Java Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Saloon Keeper
    Pie
    Posts: 2536
    113
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic