Java – Exception in thread “main” java.lang.NoClassDefFoundError: com/ibm/mq/MQException


I'm getting below exception when i run my program as below,

java -jar MQprogram.jar

I have set classpath correctly which is referring to all required jars ,
"" also referred in classpath which has MQException.

`Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/MQException
Caused by: java.lang.ClassNotFoundException:
        at$ Source)
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Program will exit.

I'm still unclear where the bug is.

Best Solution

This is almost always caused by a combination of an incomplete client install and/or a CLASSPATH issue. Many people grab the jar files rather than performing the complete install and do not necessarily get all of them. Sometimes they just keep looking up jar files and grabbing them, without regard to different versions. IBM performed a major refactor of the Java/JMS classes as of V7.0 and made some updates since then as well. As of V7.0.1, WMQ can be installed to arbitrary directory paths and multiple installs on a server. This meant that there can now be multiple JRE/s, multiple client installs, etc. This didn't affect the CLASSPATH so much but did change dependencies such as NLS support, tracing and other things the Java classes depend on/interact with.

The recommendation is to install a full WMQ client and point the CLASSPATH at the install directory. If that is not possible, then install a full client somewhere and grab the complere set of jars from the known-good installation. Then at least you know you have all the same version, etc.

Should you decide to install the full client from IBM's distribution media, you get several additional capabilities such as diagnostics and low-level trace. It also assures that maintenance can be applied. For example, you have a problem that is corrected in a Fix Pack, you simply install the Fix Pack over top of the existing client install. The Fix Pack won't install if all you have are the jar files.

The WMQ clients are available as SupportPacs. You can download one of the following:

Be sure to use the Infocenter for the version of client you are using!

Related Question