I'm very beginner of Websphere MQ classes for Java
programming.
I've decided to follow this way to write a small application able to connect and read messages from a queue through TCP/IP.
following this guide: http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.csqzaw.doc%2Fja10410_.htm
At point 4 it is suggested to test Websphere Client
installation (Version: 7.0.1.8) on windows command prompt using:
java -Djava.library.path=library_path MQIVP
where 'library_path' for me is "C:\\Program Files\\IBM\\WebSphere MQ\\java\\lib"
The application runs and I have proceeded writing a simple program with Eclipse IDE
here the code:
import com.ibm.mq.MQEnvironment;
public class MQtestMain {
public static void main(String[] args) {
System.out.println("main");
new MQtestMain();
}
public MQtestMain(){
System.out.println("MQtestMain");
MQEnvironment.hostname = "my.host.name";
MQEnvironment.channel = "my.channel";
MQEnvironment.port = 1414;
}
}
It has nothing to do but it is just a test to be sure that everything is correctly set.
I have set a custom library with both 'com.ibm.mq.jar' and 'com.ibm.mq.jmqi.jar' from "C:\\Program Files\\IBM\\WebSphere MQ\\java\\lib" and no error are reported at compile time.
Running the application from Eclipse
it correctly prints out "main" and "MQtestMain" on console.
Therefore I have proceeded to export it: File > Export > Runnable Jar
setting 'Library handling' to 'Package required libraries into generated JAR'
Unfortunately if I run the program from windows command prompt: java -jar MQtest.jar
here the result:
main
MQtestMain
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.NoClassDefFoundError: javax/resource/ResourceException
at com.ibm.mq.MQEnvironment.<clinit>(MQEnvironment.java:576)
at MQtestMain.<init>(MQtestMain.java:21)
at MQtestMain.main(MQtestMain.java:14)
... 5 more
Caused by: java.lang.ClassNotFoundException: javax.resource.ResourceException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 8 more
First and second line are correct but I really don't understand the following errors
update:
I try to give you more information:
As I've said running the application from its main class
file there are no problems, while execute it from the jar
file it seems not able to find the IBM libraries.
I have created a personal library in eclipse
named "MQ classes for Java" containig the two jar packages used by this application.
here the content of the project .classpath
file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/MQ classes for Java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Is there a way to link the correct libraries to the runnable jar in order to launch it form every machine with WMQ Client installed?
Solution:
The errors, due to some dependencies not found, have been solved including all the IBM classes for Java
jar
files into the WMQ Client
folder instalation ("C:\\Program Files\\IBM\\WebSphere MQ\\java\\lib")
您需要像使用MQIVP测试一样使用java.library.path,或者将CLASSPATH设置为包含MQ JAR文件。
Solution:
These errors are due to some dependencies not found;
they could be solved including all the IBM classes for Java
jar
files into the WMQ Client
folder instalation ("C:\\Program Files\\IBM\\WebSphere MQ\\java\\lib")
I resolved this just by adding javax dependency:
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<version>1.5</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.