简体   繁体   中英

java.lang.ClassNotFoundException: com.ibm.jms.xxxxxxxxxx

I'm working on simple project, what I'm doing is building Jar file then use a class from this jar in my project, the project running tomcat and to run servlet on it. I'm using Postman to post requests then running the servlet, in the servlet i'm trying to define a new variable then I got java.lang.ClassNotFoundException.

package coms;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.jms.JMSMessageProducer;

public class TestA extends HttpServlet  {

private static final long serialVersionUID = 1L;
private String message;

public void init() throws ServletException {
      // Do required initialization
      message = "Hello World";
   }
public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {

          JMSMessageProducer msgProdObj = new JMSMessageProducer();
          msgProdObj.send(request, response);  

       }

       public void destroy() {
          // do nothing.
       }
}

JMSMessageProducer is the class that defined in the Jar

As you can see in the classPath, the class found in the added jar, and it's imported in the code : ![在此处输入图片描述 ] 1

After searching in web I understand that the Jar should found also in WEB-INF/lib, so I added it as you can see in picture below:

在此处输入图片说明

But also this not helped.

I also saw that the code compiled without errors, it's looks like run time error.

Do any body know the problem here ?

Appreciate your efforts.

在此处输入图片说明

after deep research I find that I missing adding the jar in tomcat lanch configuration.

to do that I open tomcat configuration window 在此处输入图片说明

click "Open launch configuration"

in the Classpath tab click "Add JARs..." and add the missing JAR 在此处输入图片说明

after that restart tomcat and it's working now

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