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 IndexIBM MQ Java / JMSHow to get MQ API library version on server startup

Post new topicReply to topic
How to get MQ API library version on server startup View previous topic :: View next topic
Author Message
abhay09
PostPosted: Thu Jul 14, 2016 7:04 am Post subject: How to get MQ API library version on server startup Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 57

Hi Guys,

I am trying to get MQ Lib version via code.

I have application running on weblogic server and on server start up, I want to get MQ lib version (6,7 or

Based on version, need to perform different operations.

i check MQ docs, they have

MQJavaLevel
MQJMSLevel classes

classes that can print version

https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.javadoc.doc/WMQJavaClasses/com/ibm/mq/MQJavaLevel.html


I tried to use these classes and used reflection to call main() method on server startup and getting all print statements (Sysout) in bytearrayOutputstream

sample code:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);

PrintStream old = System.out;

System.setOut(ps);

Class javaLevel = Class.forName("com.ibm.mq.MQJavaLevel");
Method meth = javaLevel.getMethod("main", String[].class);
String[] params = {"-f","3"};
meth.invoke(null, (Object) params); // static method doesn't have an instance
System.out.flush();
System.setOut(old);
String apiLevel = baos.toString();


Above string is giving me all version for MQ8.

when tried same with MQ7 libraries, my server got crashed.

public static void main(String[] paramArrayOfString)
{
parseCommandLine(paramArrayOfString);
printMQVERInfo();
System.exit(0);
}

when checked the class it has System.exit(0); in its main() method.

So, cant call this main() method.


Please help in finding MQ library version on server startup if it is 7 or 8 or 6.


Please suggest and help.

Any help will be appreciated,
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jul 14, 2016 7:43 am Post subject: Re: How to get MQ API library version on server startup Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 24452
Location: Ohio, USA

abhay09 wrote:
Based on version, need to perform different operations.


Why? What's different?

(and why are you still using MQv6???)
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Thu Jul 14, 2016 9:33 am Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3012
Location: London, ON Canada

OMG. Talk about using a sledge-hammer when a screw-driver will work.

Here is the MQLevel class I created for the open source project Universal File Mover
Code:
package biz.capitalware.ufm.mq;

import com.ibm.mq.MQJavaLevel;

public class MQLevel extends MQJavaLevel
{
   public MQLevel()
   {
      super();
   }

   public String getName()
   {
      return queryValue(0);
   }

   public String getVersion()
   {
      return queryValue(1);
   }
}


And here's how UFM uses the MQLevel class:
Code:
try
{
   ClassLoader classLoader = ClassLoader.getSystemClassLoader();
   Class.forName("com.ibm.mq.MQJavaLevel", false, classLoader);
   MQLevel mql = new MQLevel();
   UFM.logger.info("     MQ JAR Version       = " + mql.getName()+" V"+mql.getVersion());
}
catch(ClassNotFoundException e)
{
   UFM.logger.debug("MQ is not in the CLASSPATH.");
}


Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
mqjeff
PostPosted: Thu Jul 14, 2016 9:51 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17386

If all you have is a hammer, everything looks like nails.
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
abhay09
PostPosted: Thu Jul 14, 2016 9:26 pm Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 57

RogerLacroix wrote:
OMG. Talk about using a sledge-hammer when a screw-driver will work.

Here is the MQLevel class I created for the open source project Universal File Mover
Code:
package biz.capitalware.ufm.mq;

import com.ibm.mq.MQJavaLevel;

public class MQLevel extends MQJavaLevel
{
   public MQLevel()
   {
      super();
   }

   public String getName()
   {
      return queryValue(0);
   }

   public String getVersion()
   {
      return queryValue(1);
   }
}


And here's how UFM uses the MQLevel class:
Code:
try
{
   ClassLoader classLoader = ClassLoader.getSystemClassLoader();
   Class.forName("com.ibm.mq.MQJavaLevel", false, classLoader);
   MQLevel mql = new MQLevel();
   UFM.logger.info("     MQ JAR Version       = " + mql.getName()+" V"+mql.getVersion());
}
catch(ClassNotFoundException e)
{
   UFM.logger.debug("MQ is not in the CLASSPATH.");
}


Regards,
Roger Lacroix
Capitalware Inc.


Thanks man, i will check this and let you know.
It worked well for MQJava but when tried same code to get MQJMSLevel.
got issues as MQJMSLevel also needs Component
protected static String queryValue(int id, Version.Component component)

Please suggest how to get this component?


I mean how to get MQJMS lib version?
MQJava is working but how to get MQJMS lib version


Last edited by abhay09 on Thu Jul 14, 2016 10:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
abhay09
PostPosted: Thu Jul 14, 2016 9:29 pm Post subject: Re: How to get MQ API library version on server startup Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 57

Vitor wrote:
abhay09 wrote:
Based on version, need to perform different operations.


Why? What's different?

(and why are you still using MQv6???)



I am not using MQ 6, but need generic method to get version.

Also, you might know that MQ8 has removed XA support from MQ JAVA api and i am using MQ java Api for XA for MQ 7.
Now, need to use MQ JMS API for XA for MQ version later than 7.

thats is the reason, need to check version.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Jul 15, 2016 4:01 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17386

It seems easier to change the code to always use JMS XA. Then you don't have to worry about what version of MQ is installed and then maintain two sets of code to use XA.
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Jul 15, 2016 5:24 am Post subject: Re: How to get MQ API library version on server startup Reply with quote

Grand Poobah

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

abhay09 wrote:

Also, you might know that MQ8 has removed XA support from MQ JAVA api and i am using MQ java Api for XA for MQ 7.
Now, need to use MQ JMS API for XA for MQ version later than 7.

thats is the reason, need to check version.


That's where you are mistaken. Since MQ7.5 the XA support is no longer in an additional jar file but comes with the core jar files. It has been integrated in the core product.

So no need to look for the version. Just use the latest and use XA as needed.
Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
RogerLacroix
PostPosted: Mon Jul 18, 2016 2:44 pm Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3012
Location: London, ON Canada

abhay09 wrote:
but when tried same code to get MQJMSLevel.
got issues as MQJMSLevel also needs Component
protected static String queryValue(int id, Version.Component component)

Please suggest how to get this component?

It is part of 'com.ibm.msg.client.services'.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSHow to get MQ API library version on server startup
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.