Executable Jar: JMSCC0091: The provider factory for connection type 'com.ibm.msg.client.wmq' could not be loaded

落花浮王杯 提交于 2019-12-24 14:24:05

问题


I encountered this very weird problem while working on using JMSTemplate to connect to IBM Websphere MQ. The code runs perfectly fine in Eclipse, but when I use shade plugin to package the project and all the dependencies into an Uber jar, I got this error while executing the jar file:

com.ibm.msg.client.jms.DetailedJMSException: JMSCC0091: The provider factory for  connection type 'com.ibm.msg.client.wmq' could not be loaded.
        at sun.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:437)
        at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319)
        at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:233)
        at com.ibm.msg.client.jms.internal.JmsErrorUtils.createException(JmsErrorUtils.java:109)
        at com.ibm.msg.client.jms.internal.JmsFactoryFactoryImpl.getInstance(JmsFactoryFactoryImpl.java:172)
        at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.setProviderFactory(JmsConnectionFactoryImpl.java:167)
        at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:254)
        at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6215)
        at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:120)

Here is my relevant Java code to read the keystore and truststore file as InputStream and the error happened when the method createQueueConnection was called.

InputStream keystoreInput = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystoreFile);
InputStream truststoreInput = Thread.currentThread().getContextClassLoader().getResourceAsStream(trustStoreFile);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
char[] keyPassword = keystorePassword.toCharArray();
keyStore.load(keystoreInput, keyPassword);

KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyFactory.init(keyStore, keyPassword);

KeyManager[] keyManagers = keyFactory.getKeyManagers();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());

char[] trustPassword = trustStorePassword.toCharArray();
trustStore.load(truststoreInput, trustPassword);

TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(trustStore);

TrustManager[] trustManagers = trustFactory.getTrustManagers();
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(keyManagers, trustManagers, null);
SSLContext.setDefault(sslContext);

MQQueueConnectionFactory cf = ctx.getBean("mqIdsConnectionFactory", MQQueueConnectionFactory.class);
cf.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();

I checked my xml file and all the IBM MQ dependencies are included correctly, and I can find the class files in the uber jar as well. It has been bothering me in the past few days and if anybody knows how to fix it, I would really appreciate your input and suggestions.

<dependency>
<groupId>com.ibm</groupId>
    <artifactId>com.ibm.mq</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>com.ibm.mqjms</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>com.ibm.mq.headers</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>com.ibm.mq.jmqi</artifactId>
    <version>7.5.0</version>
</dependency>        
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>dhbcore</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.jsse2</groupId>
    <artifactId>ibmjsseprovider2</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.security</groupId>
    <artifactId>ibmjcefw</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.crypto</groupId>
    <artifactId>ibmjceprovider</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.security</groupId>
    <artifactId>ibmcertpathprovider</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.security</groupId>
    <artifactId>ibmpkcs</artifactId>
    <version>7.5.0</version>
</dependency>
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>connector</artifactId>
    <version>7.5.0</version>
</dependency>

回答1:


Make sure to not extract the dependencies inside the jar but just include them as stated in the comments. If you export from within eclipse, there is a radio option to choose from.



来源:https://stackoverflow.com/questions/47794927/executable-jar-jmscc0091-the-provider-factory-for-connection-type-com-ibm-msg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!