我在使用JMSTemplate连接到IBM Websphere MQ时遇到了这个非常奇怪的问题。代码在Eclipse中运行得非常好,但是当我使用shade插件将项目和所有依赖项打包到Uber jar时,我在执行jar文件时遇到了这个错误:
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)
这是我的相关Java代码,用于将密钥库和信任库文件读取为InputStream,并且在调用方法 createQueueConnection 时发生错误。
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();
我检查了我的xml文件,并且正确包含了所有IBM MQ依赖项,我也可以在uber jar中找到类文件。在过去几天一直困扰着我,如果有人知道如何解决它,我将非常感谢您的意见和建议。
<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>
答案 0 :(得分:0)
确保不要在jar中提取依赖项,而只是按照注释中的说明包含它们。如果你从eclipse中导出,有一个无线电选项可供选择。