-7

I tried to run a thrift server and client program that was given in the thrift website and I got the below errors.Can anyone please help me out with the errors. coding can be found in : 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$ 
Goibniu
  • 2,212
  • 3
  • 34
  • 38
INIGO
  • 1
  • 2
  • 1
    Welcome to Stack Overflow. Please take the [tour] and re-visit [ask]. Your question is unclear and we are not so good at debugging code that you didn't show. Add details to your question by using the [edit] link. – rene Aug 20 '15 at 07:53
  • 2
    You have lot of compilation errors deal with one at a time. – seenukarthi Aug 20 '15 at 07:54
  • I searched for the first one and look what I found: http://stackoverflow.com/questions/22729678/java-compile-error-class-appletprac-is-public-should-be-declared-in-a-file-nam – rene Aug 20 '15 at 07:55
  • @rene i have mentioned very clearly that the code is in https://thrift.apache.org/tutorial/java ..Please do , go through it and try to help me out – INIGO Aug 20 '15 at 09:05
  • That is not how this site works. You need to provide us with an [MCVE] so future visitors only have to verify if this question matches their situation. They shouldn't have to visit some other site first. The community here has worked out over the last few years that such off-site links are not delivering a good experience. So we all have rules to follow and that includes new users. The [help] is not full of guidance to be ignored. And this might sound all unfriendly and maybe it is but at least seven members found this post unclear, as indicated by the down votes. – rene Aug 20 '15 at 09:12
  • And this is not scare you off but you might be interested in [this meta post](http://meta.stackoverflow.com/questions/255583/what-can-i-do-when-getting-we-are-no-longer-accepting-questions-answers-from-th). Stack Overflow is a great place to get help but it only is such a great place because of the strict rules the community has put together over time. – rene Aug 20 '15 at 09:16

2 Answers2

0

As far as we can deduce from what you've shown, there's a couple of things that go wrong:

  1. There seems to be an issue with your invocation of javac, it is missing a classpath that refers to the Apache Thrift library. You can specify the classpath using the -cp parameter. Make sure it points to the current directory, the Thrift libraries and any other libraries you might be using.
  2. Your class JavaServer should be declared in a file named JavaServer.java (exactly as the compiler error says). Apparently, it's called javaserver.java, which is not the same (at least not on non-Windows platforms).
mthmulders
  • 9,483
  • 4
  • 37
  • 54
  • I changed the file name to JavaServer.java ( same as class name) and now it shows me 28 errors.Can you please suggest me how to check whether thrift library for java is present or not ?? – INIGO Aug 20 '15 at 08:56
  • The command in your question (`javac javaserver.java`) doesn't show a `-cp` param, so you still need to address the first point. Take a look at [how the Java compiler works](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html). – mthmulders Aug 20 '15 at 09:05
0

Sample .thrift files attached to official web tutorial have some errors (July 2015, v0.9.x). Inconsequences in sample struct/classes etc, sample doesn't compile in few languages.

Version of this files in official tar.gz are good.

Jacek Cz
  • 1,872
  • 1
  • 15
  • 22