× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Check the optimization level on your com.ibm.mq.jar file.  It looks like
you're trying to load a class used for managed connections in an app server
environment even though you're running from a command line.  If the
optimization level is 40, try making it 30 and see if that fixes the
problem.

Gary

> -----Original Message-----
> From: java400-l-bounces@xxxxxxxxxxxx 
> [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vengoal Chang
> Sent: Wednesday, November 17, 2004 12:18 AM
> To: 'Java Programming on and around the iSeries / AS400'
> Subject: MQ client run on AS400 using java got Exception
> 
> Hi all,
>       I wrote a MQClientSample.java and I ran on AS/400 with 
> JDK 1.4.2 got following exception:
> 
> java MQClientSample 172.16.15.28 1415 
> SYSTEM.DEFAULT.LOCAL.QUEUE NET.CHANNEL AS400
>                                                               
>           
> java.lang.NoClassDefFoundError: javax/resource/spi/ConnectionManager
> 
>         at java/lang/Throwable.<init>(Throwable.java:195)
> 
>         at java/lang/Error.<init>(Error.java:49)
> 
>         at
> java/lang/NoClassDefFoundError.<init>(NoClassDefFoundError.java:40
> )
> 
>         at com/ibm/mq/MQEnvironment.<clinit>(MQEnvironment.java:110)
> 
>         at MQClientSample.<init>(MQClientSample.java:22)
> 
>         at MQClientSample.main(MQClientSample.java:269)  
> 
> But if I specified JDK 1.3,
> 
> java -Djava.version=1.3 MQClientSample 172.16.15.28 1415 
> SYSTEM.DEFAULT.LOCAL.QUEUE NET.CHANNEL AS400
> 
> Normal exit.
> 
> But If I ran the java program on PC with JDK 1.4.2, no exception.
> 
> What's problem with JDK 1.4.2 on AS/400 ?
> 
> Could you help me to solve it ?
> 
> Best regards,
> 
> Vengoal
> 
> Source as following:
>  // On AS/400:
>  // set ADDENVVAR CLASSPATH  
> '.:/QIBM/ProdData/mqm/java/lib/com.ibm.mq.jar'
>  // java -Djava.version=1.3 MQClientSample 172.16.15.28 1415 
> SYSTEM.DEFAULT.
> LOCAL.QUEUE NET.CHANNEL AS400
> 
> 
>  // On PC
>  // set CLASSPATH = %CLASSPATH%;C:\IBM\java\lib\com.ibm.mq.jar
>  // java MQClientSample
> 
> import com.ibm.mq.*;            // Include the WebSphere MQ 
> class for Java
> package
> 
> public class MQClientSample
> {
> 
>   private String hostname;                             // 
> define the name of
> your host to connect to
>   private String channel;                              // 
> define name of
> channel for client to use
>   private String qManager;                             // 
> define name of
> queue manager object to
>   private MQQueueManager qMgr;                         // 
> define a queue
> manager object
> 
>   public MQClientSample(String hostname, int port,
>                              String channel,
>                              String qmanager)
>   {
>   // When the class is called, this initialization is done first.
>      // Set up MQ environment
>      MQEnvironment.hostname = hostname;              // Could 
> have put the
> hostname & channel
>      MQEnvironment.channel  = channel;               // 
> string directly
> here!
>      MQEnvironment.port = port;
>      MQEnvironment.CCSID = 950;
>      qManager = qmanager;
>   }
>   
>   public void ConnectQmgr()
>   {
>     try 
>     {
>       // Create a connection to the queue manager
>       qMgr = new MQQueueManager(qManager);
>     }
>     // If an error has occured in the above, try to identify 
> what went wrong.
>     // Was it an MQ error?
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     } 
>   }
>   
>   public MQQueue openQ(String qName)
>   {
>     MQQueue queue = null;
>     try {
>       int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |
>                           MQC.MQOO_OUTPUT ;
>       queue = qMgr.accessQueue(qName, openOptions);
>     }
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }                                          
>       return queue;
>   }
>   
>   public void closeQ(MQQueue queue)
>   {
>     try {
>       queue.close();
>     }
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }                                          
>   }
>   
>   public void disconnectQmgr()
>   {
>     try {
>       qMgr.disconnect();
>     }
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }                                          
>   }      
>   
>   public void putMsg(MQQueue queue, String msgStr, int characterSet)
>   {
>     MQMessage mqmessage = null;
>     try 
>     {
>       mqmessage = new MQMessage();
>       mqmessage.format = MQC.MQFMT_STRING;
>       mqmessage.characterSet = characterSet;
>       mqmessage.writeString(msgStr);
>       MQPutMessageOptions pmo = new MQPutMessageOptions();
>       queue.put(mqmessage,pmo);       
>       
>     }
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }
>     // Was it a Java buffer space error?
>     catch (java.io.IOException ex)
>     {
>       System.out.println("An error occurred whilst writing to 
> the message
> buffer: " +
>                          ex);
>       ex.printStackTrace();
>     }                                                         
>   }
>   
>   public String getMsg(MQQueue queue, int wait)
>   {
>     String msgText=null;
>     MQMessage retrievedMessage = null;
>     try 
>     {
>       retrievedMessage = new MQMessage();
>       MQGetMessageOptions gmo = new MQGetMessageOptions();
>       if (wait > 0) 
>       {
>               gmo.options= MQC.MQGMO_WAIT;
>               gmo.waitInterval = wait;
>       }
>       queue.get(retrievedMessage, gmo);
>       int msgLen = retrievedMessage.getTotalMessageLength();
>       byte as400data[] = new byte [msgLen];
>       retrievedMessage.readFully(as400data);
>       if (retrievedMessage.characterSet == 937)
>       {
>          msgText = new String(as400data,"Cp937");
>       }
>       if (retrievedMessage.characterSet == 950)
>       {
>          msgText = new String(as400data,"Cp950");
>       }
>     }
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }
>     // Was it a Java buffer space error?
>     catch (java.io.IOException ex)
>     {
>       System.out.println("An error occurred whilst writing to 
> the message
> buffer: " +
>                          ex);
>       ex.printStackTrace();
>     }    
>     
>     return msgText;
>   }
> 
>   public void MQClientPutGet()
>   {
> 
>     try {
>       // Create a connection to the queue manager
>       qMgr = new MQQueueManager(qManager);
> 
>       // Set up the options on the queue we wish to open...
>       // Note. All MQ Options are prefixed with MQC in Java.
> 
>       int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |
>                         MQC.MQOO_OUTPUT ;
> 
>       // Now specify the queue that we wish to open, and the 
> open options...
> 
>       MQQueue system_default_local_queue =
>               qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",
>                                openOptions,
>                                null,           // default q manager
>                                null,           // no dynamic q name
>                                null);          // no alternate user id
> 
> 
>       // Define a simple MQ message, and initialise it in UTF format..
> 
>       MQMessage hello_world = new MQMessage();
>       hello_world.format = MQC.MQFMT_STRING;
>       hello_world.characterSet = 950;               
>       hello_world.writeString("Hello World!你好");
> 
>       System.out.println("After Writing ...");
> 
>       // specify the message options...
> 
>       MQPutMessageOptions pmo = new MQPutMessageOptions();  
> // accept the defaults, same
>                                                             
> // as MQPMO_DEFAULT constant
> 
>       // put the message on the queue
> 
>       system_default_local_queue.put(hello_world,pmo);  
> 
>       // get the message back again...
>       // First define a MQ message buffer to receive the 
> message into..
> 
>       MQMessage retrievedMessage = new MQMessage();
>       retrievedMessage.messageId = hello_world.messageId;
> 
>       // Set the get message options..
> 
>       MQGetMessageOptions gmo = new MQGetMessageOptions();  
> // accept the defaults
>                                                             
> // same as MQGMO_DEFAULT
> 
>       // get the message off the queue..
>       System.out.println("before Read ...");
>       system_default_local_queue.get(retrievedMessage,
>                                      gmo,
>                                      100);              // 
> max message size
> 
>       // And prove we have the message by displaying the UTF 
> message text
>       int msgLen = retrievedMessage.getTotalMessageLength();
>       byte as400data[] = new byte [msgLen];
>       retrievedMessage.readFully(as400data);
>       String msgText=null;
>       if (retrievedMessage.characterSet == 937)
>       {
>          msgText = new String(as400data,"Cp937");
>       }
>       if (retrievedMessage.characterSet == 950)
>       {
>          msgText = new String(as400data,"Cp950");
>       }
>       //String msgText = retrievedMessage.readUTF();
>       //String msgText = retrievedMessage.readString(msgLen);      
>       System.out.println("After Read ...");      
>       System.out.println("The message is: " + msgText);
> 
>       // Close the queue
> 
>       system_default_local_queue.close();
> 
>       // Disconnect from the queue manager
> 
>       qMgr.disconnect();
> 
>     }
> 
>     // If an error has occured in the above, try to identify 
> what went wrong.
>     // Was it an MQ error?
> 
>     catch (MQException ex)
>     {
>       System.out.println("An MQ error occurred : Completion code " +
>                          ex.completionCode +
>                          " Reason code " + ex.reasonCode);
>     }
>     // Was it a Java buffer space error?
>     catch (java.io.IOException ex)
>     {
>       System.out.println("An error occurred whilst writing to 
> the message
> buffer: " +
>                          ex);
>     }
> 
>   } // end MQclientPutGet
> 
>   public static void main(String args[])
>   {
>       System.out.println("Usage: java MQClientSample host 
> port openqueue channel qmanager");
> //    String hostname = "172.16.15.28";
> //    String channel = "NET.CHANNEL";
> //    String qmanager = "AS400";
> //    int port =1415;
>       String hostname = args[0];
>       String openqueue = args[2];
>       String channel = args[3];
>       String qmanager = args[4];
>       int port = Integer.parseInt(args[1]);   
>       MQClientSample mqclient = new MQClientSample(hostname, 
> port, channel, qmanager);
> //    mqclient.MQClientPutGet();
>       mqclient.ConnectQmgr();
>       MQQueue queue = mqclient.openQ(openqueue);
>       mqclient.putMsg(queue, "Hello World!你好", 950);
>       String msgText = mqclient.getMsg(queue,0);
>         System.out.println("The message is: " + msgText); 
>         mqclient.closeQ(queue);
>         mqclient.disconnectQmgr();    
>       System.exit(0);
>   }  
> 
> } // end of sample
>            
> 
> 
> 
> --
> This is the Java Programming on and around the iSeries / 
> AS400 (JAVA400-L) mailing list To post a message email: 
> JAVA400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change 
> list options,
> visit: http://lists.midrange.com/mailman/listinfo/java400-l
> or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, 
> please take a moment to review the archives at 
> http://archive.midrange.com/java400-l.
> 



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.