使用Apache Thrift时出现编译错误

时间:2015-08-20 07:47:04

标签: java thrift

我试图在thrift网站上运行一个thrift服务器和客户端程序,我得到了以下错误。任何人都可以帮我解决错误。 编码可在以下网址找到:https://thrift.apache.org/tutorial/java

naren@naren:~/Desktop$ javac javaserver.java 
javaserver.java:16: error: class JavaServer is public, should be declared in a file named JavaServer.java
public class JavaServer {
       ^
javaserver.java:1: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TServer;
                               ^
javaserver.java:2: error: package org.apache.thrift.server.TServer does not exist
import org.apache.thrift.server.TServer.Args;
                                       ^
javaserver.java:3: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TSimpleServer;
                               ^
javaserver.java:4: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TThreadPoolServer;
                               ^
javaserver.java:5: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TSSLTransportFactory;
                                  ^
javaserver.java:6: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TServerSocket;
                                  ^
javaserver.java:7: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TServerTransport;
                                  ^
javaserver.java:8: error: package org.apache.thrift.transport.TSSLTransportFactory does not exist
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
                                                       ^
javaserver.java:11: error: package tutorial does not exist
import tutorial.*;
^
javaserver.java:12: error: package shared does not exist
import shared.*;
^
javaserver.java:18: error: cannot find symbol
  public static CalculatorHandler handler;
                ^
  symbol:   class CalculatorHandler
  location: class JavaServer
javaserver.java:20: error: package Calculator does not exist
  public static Calculator.Processor processor;
                          ^
javaserver.java:45: error: package Calculator does not exist
  public static void simple(Calculator.Processor processor) {
                                      ^
javaserver.java:58: error: package Calculator does not exist
  public static void secure(Calculator.Processor processor) {
                                      ^
javaserver.java:24: error: cannot find symbol
      handler = new CalculatorHandler();
                    ^
  symbol:   class CalculatorHandler
  location: class JavaServer
javaserver.java:25: error: package Calculator does not exist
      processor = new Calculator.Processor(handler);
                                ^
javaserver.java:47: error: cannot find symbol
      TServerTransport serverTransport = new TServerSocket(9090);
      ^
  symbol:   class TServerTransport
  location: class JavaServer
javaserver.java:47: error: cannot find symbol
      TServerTransport serverTransport = new TServerSocket(9090);
                                             ^
  symbol:   class TServerSocket
  location: class JavaServer
javaserver.java:48: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
      ^
  symbol:   class TServer
  location: class JavaServer
javaserver.java:48: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
                           ^
  symbol:   class TSimpleServer
  location: class JavaServer
javaserver.java:48: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
                                             ^
  symbol:   class Args
  location: class JavaServer
javaserver.java:61: error: cannot find symbol
      TSSLTransportParameters params = new TSSLTransportParameters();
      ^
  symbol:   class TSSLTransportParameters
  location: class JavaServer
javaserver.java:61: error: cannot find symbol
      TSSLTransportParameters params = new TSSLTransportParameters();
                                           ^
  symbol:   class TSSLTransportParameters
  location: class JavaServer
javaserver.java:65: error: cannot find symbol
      TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
      ^
  symbol:   class TServerTransport
  location: class JavaServer
javaserver.java:65: error: cannot find symbol
      TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
                                         ^
  symbol:   variable TSSLTransportFactory
  location: class JavaServer
javaserver.java:66: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
      ^
  symbol:   class TServer
  location: class JavaServer
javaserver.java:66: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
                           ^
  symbol:   class TSimpleServer
  location: class JavaServer
javaserver.java:66: error: cannot find symbol
      TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
                                             ^
  symbol:   class Args
  location: class JavaServer
29 errors
naren@naren:~/Desktop$ 

2 个答案:

答案 0 :(得分:0)

就我们可以推断出你所展示的内容而言,有一些问题出现了:

  1. 您调用<applicationPool>似乎存在问题,它缺少引用Apache Thrift库的类路径。您可以使用javac参数指定类路径。确保它指向当前目录,Thrift库以及您可能正在使用的任何其他库。
  2. 您的类-cp应在名为JavaServer的文件中声明(与编译器错误所述完全相同)。显然,它被称为JavaServer.java,它不相同(至少不在非Windows平台上)。

答案 1 :(得分:0)

附加到官方网络教程的示例.thrift文件有一些错误(2015年7月,v0.9.x)。 样本结构/类等的后果,样本不能用少量语言编译。

官方tar.gz中此文件的版本很好。