Java ClassNotFoundException:com.ibm.mq.jms.MQConnectionFactory(Websphere mq 7.5+;spring jms+;maven tomcat 7插件)
我试图创建一个简单的Webapp来演示如何在Servlet容器(tomcat)中使用WMQ 7.5。我的网络地图基于独立的WMQ示例应用程序。 我的独立应用程序运行良好。 测试用例也很好。Java ClassNotFoundException:com.ibm.mq.jms.MQConnectionFactory(Websphere mq 7.5+;spring jms+;maven tomcat 7插件),java,tomcat7,maven-3,ibm-mq,spring-jms,Java,Tomcat7,Maven 3,Ibm Mq,Spring Jms,我试图创建一个简单的Webapp来演示如何在Servlet容器(tomcat)中使用WMQ 7.5。我的网络地图基于独立的WMQ示例应用程序。 我的独立应用程序运行良好。 测试用例也很好。 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppConfig.class) public class MQMessageTest { /** * Message count fot tes
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
public class MQMessageTest {
/**
* Message count fot test
*/
private static final int MESSAGE_COUNT = 25;
/**
* Setting Environment for getting properties
*/
@Autowired
private Environment environment;
/**
* MQMessageSender for sending messages
*/
@Autowired
private MQMessageSender mqMessageSender;
/**
* JmsTemplate of Spring JMS
*/
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void testEqualsOfSentAndReceivedMessages() {
/*Sending messages to Queue*/
for (int i = 0; i < MESSAGE_COUNT; i++) {
mqMessageSender.send("Message with" + System.nanoTime());
}
/*Container for received messages*/
Set<TextMessage> messages = new HashSet<TextMessage>();
/*Receiving messages from report Queue*/
for (int i = 0; i < MESSAGE_COUNT; i++) {
TextMessage message = (TextMessage) jmsTemplate.receive(environment.getRequiredProperty("wmq.queue.test.input.2"));
messages.add(message);
}
assertEquals(messages.size(), MESSAGE_COUNT);
}
}
请告诉我有什么问题。我如何解决它?何时需要修复:在tomcat、websphere MQ或spring jms中?我试图与jetty合作,但失败了。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
public class MQMessageTest {
/**
* Message count fot test
*/
private static final int MESSAGE_COUNT = 25;
/**
* Setting Environment for getting properties
*/
@Autowired
private Environment environment;
/**
* MQMessageSender for sending messages
*/
@Autowired
private MQMessageSender mqMessageSender;
/**
* JmsTemplate of Spring JMS
*/
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void testEqualsOfSentAndReceivedMessages() {
/*Sending messages to Queue*/
for (int i = 0; i < MESSAGE_COUNT; i++) {
mqMessageSender.send("Message with" + System.nanoTime());
}
/*Container for received messages*/
Set<TextMessage> messages = new HashSet<TextMessage>();
/*Receiving messages from report Queue*/
for (int i = 0; i < MESSAGE_COUNT; i++) {
TextMessage message = (TextMessage) jmsTemplate.receive(environment.getRequiredProperty("wmq.queue.test.input.2"));
messages.add(message);
}
assertEquals(messages.size(), MESSAGE_COUNT);
}
}
我的POM
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>by.iba</groupId>
<artifactId>mqservice-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Web MQ Module</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<websphereMq.version>7.5.0.2</websphereMq.version>
<wmq.jars>${basedir}/lib</wmq.jars>
<spring.version>4.0.6.RELEASE</spring.version>
</properties>
<dependencies>
<!--Websphere MQ dependencies-->
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqjms</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mqjms.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.headers</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mq.headers.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.jmqi</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mq.jmqi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.dhbcore</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/dhbcore.jar</systemPath>
</dependency>
<!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--Javax Servlet API-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--Junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Jetty Plugin -->
<!--<plugin>-->
<!--<groupId>org.mortbay.jetty</groupId>-->
<!--<artifactId>maven-jetty-plugin</artifactId>-->
<!--<version>6.1.10</version>-->
<!--</plugin>-->
<!-- Set JDK Compiler Level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- Tomcat Plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>local_tomcat</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warName>mqservice-webapp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
WEB初始值设定项
public class WebInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
非常感谢。对不起,我的英语不好。最后的战争包括MQ jar文件吗?我认为这是一个IBMMQJAR文件丢失的构建问题,因此ClassNotFoundException 我建议使用maven的文件系统存储库,而不是使用systempath直接链接到源代码。参考将MQ JAR添加到此存储库,并将其作为依赖项添加到POM中
另一个选项是在catalina.properties中使用共享类加载器。在这里,您可以直接从/opt/mqm/java/lib加载mqjar。我使用gradle而不是maven解决了这个问题。这个项目现在很小。我认为格拉德尔有更好的机会。谢谢你的回答。你平静的劝告是好的。很遗憾,我不能投票赞成你的答案。我没有理由这样做。
public class WebInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}