I’m trying to export an Eclipse project to a JAR executable file.
This project include a personal library with two IBM packages com.ibm.mq.jar and com.ibm.mq.jmqi.jar
There are no errors running the application from Eclipse run button or by command: java MainClass from the project bin folder.
Unfortunately once the jar is created (File > Export > Runnable Jar) and launched java -jar MainClass.jar this is the result:
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(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: javax/resource/ResourceException
at com.ibm.mq.MQEnvironment.<clinit>(MQEnvironment.java:520)
at MQtestMain.<init>(MQtestMain.java:38)
at MQtestMain.main(MQtestMain.java:18)
... 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
I have tried also Fat Jar plugin for the export but the result of java -jar MainClass_fat.jar is quite similar:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/resource/ResourceException
at com.ibm.mq.MQEnvironment.<clinit>(MQEnvironment.java:520)
at MQtestMain.<init>(MQtestMain.java:38)
at MQtestMain.main(MQtestMain.java:18)
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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
Which is the correct way to export and run an Eclipse project to a Jar file including IBM MQ Classes for Java libraries?
Update 1: Unecessary but very useful to reach the solution.
Suggested by Integrating Stuff:
Include javaee.jar file from the Java EE installation to import all dependencies for IBM classes jar included into the project.
Solution: Respect all the IBM classes for Java dependencies.
Import into the custom library ALL the jar file from C:\...\IBM\WebSphere MQ\java\lib
export as runnable Jar from Eclipse (Fat Jar plugin is not needed also)
Solution: Respect all the IBM classes for Java dependencies.
I’ve found very useful Integrating Stuff suggest to include
javaee.jarfile from the Java EE installation to import all dependencies for IBM classes jar included into the project.This doesn’t resolve the error he but has led me to the solution:
Import into the custom library ALL the
jarfile fromC:\...\IBM\WebSphere MQ\java\libexport as runnable Jar from
Eclipse(Fat Jar plugin is not needed also)