简体   繁体   English

Eclipse:Tomcat Servlet内部节俭,ClassNotFoundException TException

[英]Eclipse: Thrift inside Tomcat Servlet, ClassNotFoundException TException

I'm trying to make a Java servlet that can make Apache Thrift calls, but I'm having trouble starting the servlet. 我正在尝试制作一个可以进行Apache Thrift调用的Java servlet,但是在启动servlet时遇到了麻烦。

I have a thrift client , a Java class for making calls to the thrift server 我有一个Thrift客户端 ,这是一个用于调用Thrift服务器的Java类

public class ThriftClient {

    static TTransport transport;
    static TProtocol protocol;
    static MyService.Client client;

    static long xtk_pointer;

    public static void openSocket() throws TException {
        transport = new TSocket("localhost", 9090);
        transport.open();

        protocol = new TBinaryProtocol(transport);
        client = new MyService.Client(protocol);
    }

and I have a java servlet which opens a socket through the thrift client 我有一个Java Servlet ,它通过Thrift客户端打开套接字

public class MyServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        out.println("Hello World");
    }

    void startThrift(String [] args) {
        try {
            ThriftClient.openSocket();

However, when I try to run this servlet (using eclipse and a tomcat server), I get an error like 但是,当我尝试运行此servlet(使用eclipse和tomcat服务器)时,出现类似以下错误

SEVERE: A child container failed during start

and a ClassNotFoundException for org.apache.thrift.TException org.apache.thrift.TExceptionClassNotFoundException

EDIT: All I had to do was include the thrift jars into the Tomcat Server's classpath. 编辑:我所要做的就是将旧罐子添加到Tomcat服务器的类路径中。 See my answer below 请参阅下面的答案

I have used the thrift client already without any ClassNotFoundExceptions, and the servlet works on its own as well. 我已经使用过节俭的客户端,而没有任何ClassNotFoundExceptions,并且servlet也可以独立工作。 However, once I add ThriftClient.openSocket(); 但是,一旦添加ThriftClient.openSocket(); into the servlet, it breaks, so I have a feeling Thrift and Tomcat are clashing somehow. 进入servlet时,它会中断,因此我感到Thrift和Tomcat在某种程度上发生了冲突。 Any ideas? 有任何想法吗?

Edit: The weird part is that I never call the method startThrift() but I still get the error. 编辑:奇怪的是,我从来没有调用方法startThrift()但我仍然收到错误。

While you included the thrift jars into your project, you also have to add them to the Tomcat library as well 在将Thrift jars包含到项目中的同时,还必须将它们添加到Tomcat库中

First make sure your external jars are in your project Java Build Path... 首先确保您的外部jar位于项目Java Build Path中。

  1. right click your project, click Properties 右键单击您的项目,单击Properties
  2. Under Deployment Assembly , click Add... 在“ Deployment Assembly ,单击“ Add...
  3. Double click Java Build Path Entries... and select the jars/libraries you want to include 双击Java Build Path Entries...然后选择要包含的jar /库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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