简体   繁体   中英

How export an Eclipse project including IBM classes for Java libraries into an executable JAR

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)

javax.resource.ResourceException is part of the Java EE api.

Your Eclipse project probably assumes this jar is going to be available in the target environment/does not have the java-ee api in its list of jars to package with the application.

Which build tool are you using? Maven or Ant, or are you packaging in Eclipse itself, without using an external tool?

To solve the problem, you need to make sure the Java EE api jar is included in your executable jar.

Solution: Respect all the IBM classes for Java dependencies.

I've found very useful Integrating Stuff suggest to include javaee.jar file 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 jar file from C:\\...\\IBM\\WebSphere MQ\\java\\lib
export as runnable Jar from Eclipse (Fat Jar plugin is not needed also)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM