ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » JAVA API code in "usning java" is dated ? API is

Post new topic  Reply to topic Goto page 1, 2, 3  Next
 JAVA API code in "usning java" is dated ? API is « View previous topic :: View next topic » 
Author Message
anotherID
PostPosted: Tue Jun 21, 2011 6:51 am    Post subject: JAVA API code in "usning java" is dated ? API is Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

Hi,

I just have to test connection to Q-manager using java.

Here is the code I took from the net and try to use updated options for MQQueue.

Here is the code:

Code:
# cat MQSample.java
import  com.ibm.mq.*;           


 
public class MQSample
{
  private String qManager = "your_Q_manager"; 
                                               
  private MQQueueManager qMgr;                 
                                             
  public static void main(String args[]) {
     new MQSample();
  }
 
  public MQSample() {
   try {
   
      qMgr = new MQQueueManager(qManager);
 
     
      int openOptions =  CMQC.MQOO_BROWSE ; // CMQC.MQOO_INPUT_AS_Q_DEF |
                        //CMQC.MQOO_OUTPUT ;     
 
     
      MQQueue system_default_local_queue =
              qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",
                               openOptions);
                                     
 
      MQMessage hello_world = new MQMessage();
      hello_world.writeUTF("Hello World!"); 
 
 
      MQPutMessageOptions pmo = new MQPutMessageOptions();
   
      system_default_local_queue.put(hello_world,pmo);
 
   
      MQMessage retrievedMessage = new MQMessage();
      retrievedMessage.messageId = hello_world.messageId;
 
      MQGetMessageOptions gmo = new MQGetMessageOptions();
   
      system_default_local_queue.get(retrievedMessage, gmo);
   
 
      String msgText = retrievedMessage.readUTF();
      System.out.println("The message is: " + msgText);
     
      system_default_local_queue.close();
 
 
      qMgr.disconnect();
    }
   
    catch (MQException ex)
    {
      System.out.println("A WebSphere MQ error occurred : Completion code " +
                         ex.completionCode + " Reason code " + ex.reasonCode);
    }
     
    catch (java.io.IOException ex)
    {
      System.out.println("An error occurred whilst writing to the message buffer: " + ex);
    }
  }
}



That is the error I get when I compile:

Code:
# javac MQSample.java
MQSample.java:23: cannot find symbol
symbol  : variable CMQC
location: class MQSample
      int openOptions =  CMQC.MQOO_BROWSE ;
                         ^
1 error



That what I have installed:
Code:

# rpm   -aq | grep -i mq
MQSeriesClient-7.0.1-3.i386
MQSeriesKeyMan-7.0.1-3.i386
MQSeriesFTA-7.0.1-3.i386
MQSeriesSamples-7.0.1-3.i386
MQSeriesRuntime-7.0.1-3.i386
MQSeriesTXClient-7.0.1-3.i386
MQSeriesServer-7.0.1-3.i386
MQSeriesJava-7.0.1-3.i386
MQSeriesConfig-7.0.1-3.i386
MQSeriesEclipseSDK33-7.0.1-3.i386
MQSeriesJRE-7.0.1-3.i386
MQSeriesSDK-7.0.1-3.i386

Thanks.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Jun 21, 2011 6:57 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.javadoc.doc/WMQJavaClasses/com/ibm/mq/constants/CMQC.html
Back to top
View user's profile Send private message
anotherID
PostPosted: Tue Jun 21, 2011 7:21 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

I am sorry but that link is not much help to me.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 21, 2011 11:02 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

anotherID wrote:
I am sorry but that link is not much help to me.

I thought you understood java? Seems like you are missing jars on your classpath, or that one of your import statements may need to be changed...

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
anotherID
PostPosted: Tue Jun 21, 2011 11:52 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

I followed the instruction to set it up.

Code:
# echo $CLASSPATH
/opt/mqm/java/lib/com.ibm.mq.jar:/opt/mqm/java/lib/connector.jar:/opt/mqm/java/lib



Code:

 ls /opt/mqm/java/lib/
CL3Export.jar                  com.ibm.mq.jmqi.jar        dhbcore.jar    libmqjbnd.so
CL3Nonexport.jar               com.ibm.mqjms.jar          fscontext.jar  libmqjexitstub02.so
com.ibm.mq.axis2.jar           com.ibm.mq.jms.Nojndi.jar  jca            libPgmIpLayer.so
com.ibm.mq.commonservices.jar  com.ibm.mq.pcf.jar         jdbc           OSGi
com.ibm.mq.defaultconfig.jar   com.ibm.mq.postcard.jar    jms.jar        providerutil.jar
com.ibm.mqetclient.jar         com.ibm.mq.soap.jar        jndi.jar       rmm.jar
com.ibm.mq.headers.jar         com.ibm.mq.tools.ras.jar   jta.jar        soap
com.ibm.mq.jar                 connector.jar              ldap.jar
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 21, 2011 12:55 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

anotherID wrote:
I followed the instruction to set it up.

Code:
# echo $CLASSPATH
/opt/mqm/java/lib/com.ibm.mq.jar:/opt/mqm/java/lib/connector.jar:/opt/mqm/java/lib



Code:

 ls /opt/mqm/java/lib/
CL3Export.jar                  com.ibm.mq.jmqi.jar        dhbcore.jar    libmqjbnd.so
CL3Nonexport.jar               com.ibm.mqjms.jar          fscontext.jar  libmqjexitstub02.so
com.ibm.mq.axis2.jar           com.ibm.mq.jms.Nojndi.jar  jca            libPgmIpLayer.so
com.ibm.mq.commonservices.jar  com.ibm.mq.pcf.jar         jdbc           OSGi
com.ibm.mq.defaultconfig.jar   com.ibm.mq.postcard.jar    jms.jar        providerutil.jar
com.ibm.mqetclient.jar         com.ibm.mq.soap.jar        jndi.jar       rmm.jar
com.ibm.mq.headers.jar         com.ibm.mq.tools.ras.jar   jta.jar        soap
com.ibm.mq.jar                 connector.jar              ldap.jar


So what? you are still missing a jar on your classpath.

To find out which you can try a jar -tvf of the different jar files and see where you find MQConstants ??
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
anotherID
PostPosted: Tue Jun 21, 2011 6:37 pm    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

No jar file has that string. Should I add every single jar file in the class path and then try?

Is this because this package is from IBM and its trial version ?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 21, 2011 9:01 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

anotherID wrote:
No jar file has that string. Should I add every single jar file in the class path and then try?

Sounds like your best idea so far
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
anotherID
PostPosted: Wed Jun 22, 2011 6:43 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

Ok I do that.
I hope there is a happy ending to all this.
Back to top
View user's profile Send private message
anotherID
PostPosted: Wed Jun 22, 2011 6:59 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

nope.


this is my class path.

Code:
# echo $CLASSPATH
/opt/mqm/java/lib/com.ibm.mq.jar:
/opt/mqm/java/lib/connector.jar:
/opt/mqm/java/lib:
/opt/mqm/java/lib/com.ibm.mq.tools.ras.jar:
/opt/mqm/java/lib/soap/servlet.jar:
/opt/mqm/java/lib/soap/jaxrpc.jar:
/opt/mqm/java/lib/soap/commons-logging-1.0.4.jar:
/opt/mqm/java/lib/soap/commons-discovery-0.2.jar:
/opt/mqm/java/lib/soap/wsdl4j-1.5.1.jar:
/opt/mqm/java/lib/soap/saaj.jar:
/opt/mqm/java/lib/providerutil.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.wmq.prereq_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.jms_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.wmq.nls_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.commonservices.j2se_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.wmq_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.mq.osgi.xa_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.jms.prereq_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.mq.osgi.directip_7.0.1.3.jar:
/opt/mqm/java/lib/OSGi/com.ibm.msg.client.osgi.nls_7.0.1.3.jar:
/opt/mqm/java/lib/com.ibm.mq.axis2.jar:
/opt/mqm/java/lib/com.ibm.mq.postcard.jar:
/opt/mqm/java/lib/jta.jar:
/opt/mqm/java/lib/com.ibm.mq.jar:
/opt/mqm/java/lib/com.ibm.mq.pcf.jar:
/opt/mqm/java/lib/com.ibm.mq.headers.jar:
/opt/mqm/java/lib/jndi.jar:
/opt/mqm/java/lib/dhbcore.jar:
/opt/mqm/java/lib/CL3Nonexport.jar:
/opt/mqm/java/lib/com.ibm.mq.jmqi.jar:
/opt/mqm/java/lib/com.ibm.mqetclient.jar:
/opt/mqm/java/lib/rmm.jar:
/opt/mqm/java/lib/ldap.jar:
/opt/mqm/java/lib/CL3Export.jar:
/opt/mqm/java/lib/com.ibm.mqjms.jar:
/opt/mqm/java/lib/com.ibm.mq.soap.jar:
/opt/mqm/java/lib/fscontext.jar:
/opt/mqm/java/lib/com.ibm.mq.jms.Nojndi.jar:
/opt/mqm/java/lib/connector.jar:
/opt/mqm/java/lib/jms.jar:
/opt/mqm/java/lib/com.ibm.mq.commonservices.jar:
/opt/mqm/java/lib/com.ibm.mq.defaultconfig.jar


the call:

Code:
 int openOptions =  CMQC.MQOO_BROWSE ;



Code:
The error:

]# javac MQSample.java
MQSample.java:21: cannot find symbol
symbol  : variable CMQC
location: class MQSample
      int openOptions =  CMQC.MQOO_BROWSE ; // CMQC.MQOO_INPUT_AS_Q_DEF |
                         ^
1 error



What Is not so reasonable here is, I found that call "CMQC.MQOO_BROWSE" from the documents which came with this whole software package.

Out of all sciences comp-science sucks the most.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jun 22, 2011 7:05 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Add an *explicit* import for com.ibm.mq.constants.CMQC.
Back to top
View user's profile Send private message
anotherID
PostPosted: Wed Jun 22, 2011 7:47 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

mqjeff wrote:
Add an *explicit* import for com.ibm.mq.constants.CMQC.


That worked.

Thanks.
Back to top
View user's profile Send private message
anotherID
PostPosted: Wed Jun 22, 2011 8:48 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

ok It compiles fine now.

but when I run it I get following error.

Code:
# java MQSample
MQJE001: Completion Code '2', Reason '2495'.
A WebSphere MQ error occurred : Completion code 2 Reason code 2495



Plus is there any javac compiler options to get detailed debug information?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jun 22, 2011 9:12 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.amqzao.doc/fm20540_.htm
Back to top
View user's profile Send private message
anotherID
PostPosted: Wed Jun 22, 2011 9:20 am    Post subject: Reply with quote

Novice

Joined: 21 Jun 2011
Posts: 19

Thanks but I figured it out.

After setting up

Code:
export LD_LIBRARY_PATH=/opt/mqm/java/lib/


that error went away..

Now I am getting

Code:
MQJE001: Completion Code '2', Reason '2058'
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2, 3  Next Page 1 of 3

MQSeries.net Forum Index » IBM MQ Java / JMS » JAVA API code in "usning java" is dated ? API is
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.