Author |
Message
|
abhay09 |
Posted: Thu Jul 14, 2016 7:04 am Post subject: How to get MQ API library version on server startup |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
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 |
|
 |
Vitor |
Posted: Thu Jul 14, 2016 7:43 am Post subject: Re: How to get MQ API library version on server startup |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, 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 |
|
 |
RogerLacroix |
Posted: Thu Jul 14, 2016 9:33 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 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 |
|
 |
mqjeff |
Posted: Thu Jul 14, 2016 9:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If all you have is a hammer, everything looks like nails. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
abhay09 |
Posted: Thu Jul 14, 2016 9:26 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
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 |
|
 |
abhay09 |
Posted: Thu Jul 14, 2016 9:29 pm Post subject: Re: How to get MQ API library version on server startup |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
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 |
|
 |
mqjeff |
Posted: Fri Jul 15, 2016 4:01 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
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. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jul 15, 2016 5:24 am Post subject: Re: How to get MQ API library version on server startup |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 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 |
|
 |
RogerLacroix |
Posted: Mon Jul 18, 2016 2:44 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 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 |
|
 |
|