Apache 使用com.ning.http.client.asynchHandler时发生NoClassDefFoundError

Apache 使用com.ning.http.client.asynchHandler时发生NoClassDefFoundError,apache,spark-streaming,receiver,ning,Apache,Spark Streaming,Receiver,Ning,在Szelvenskiyth模板获得http URL作为输入之后,我正在为ApacheSpark构建一个接收器。我可以用sbt打包jar,但在运行时应用程序会抛出java.lang.NoClassDefFoundError:com.ning.http.client.AsyncHandler异常。请在此处找到实现接收器的代码: import org.apache.spark.streaming.receiver.Receiver import org.apache.spark.storage.St

在Szelvenskiyth模板获得http URL作为输入之后,我正在为ApacheSpark构建一个接收器。我可以用sbt打包jar,但在运行时应用程序会抛出java.lang.NoClassDefFoundError:com.ning.http.client.AsyncHandler异常。请在此处找到实现接收器的代码:

import org.apache.spark.streaming.receiver.Receiver
import org.apache.spark.storage.StorageLevel
import org.apache.spark.Logging
import com.ning.http.client.AsyncHttpClientConfig
import com.ning.http.client.AsyncHandler
import com.ning.http.client.AsyncHttpClient
import com.ning.http.client._
import scala.collection.mutable.ArrayBuffer
import java.io.OutputStream
import java.io.ByteArrayInputStream
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.InputStream
import java.io.PipedInputStream
import java.io.PipedOutputStream

class ParkingReceiver(url: String) extends Receiver[String](StorageLevel.MEMORY_AND_DISK_2) with Logging {

  @transient var client: AsyncHttpClient = _ 
  @transient var inputPipe: PipedInputStream = _
  @transient var outputPipe: PipedOutputStream = _  

  def onStart() {    
    val cf = new AsyncHttpClientConfig.Builder()
    cf.setRequestTimeout(Integer.MAX_VALUE)
    cf.setReadTimeout(Integer.MAX_VALUE)
    cf.setPooledConnectionIdleTimeout(Integer.MAX_VALUE)      
    client= new AsyncHttpClient(cf.build())

    inputPipe = new PipedInputStream(1024 * 1024)
    outputPipe = new PipedOutputStream(inputPipe)
    val producerThread = new Thread(new DataConsumer(inputPipe))
    producerThread.start()

    client.prepareGet(url).execute(new AsyncHandler[Unit]() {

      def onBodyPartReceived(bodyPart: HttpResponseBodyPart) = {
        bodyPart.writeTo(outputPipe)
        AsyncHandler.STATE.CONTINUE        
      }

      def onStatusReceived(status: HttpResponseStatus) = {
        AsyncHandler.STATE.CONTINUE
      }

      def onHeadersReceived(headers: HttpResponseHeaders) = {
        AsyncHandler.STATE.CONTINUE
      }

      def onCompleted = {
        println("completed")
      }


      def onThrowable(t: Throwable)={
        t.printStackTrace()
      }

    })    


  }

  def onStop() {
    if (Option(client).isDefined) client.close()
    if (Option(outputPipe).isDefined) {
     outputPipe.flush()
     outputPipe.close() 
    }
    if (Option(inputPipe).isDefined) {
     inputPipe.close() 
    }    
  }

  class DataConsumer(inputStream: InputStream) extends Runnable 
  {

      override
      def run()
      {        
        val bufferedReader = new BufferedReader( new InputStreamReader( inputStream ))
        var input=bufferedReader.readLine()
        while(input!=null){          
          store(input)
          input=bufferedReader.readLine()
        }            
      }     
  }
}

你们中有没有人曾经经历过这种情况,或者可能知道代码中缺少了什么?

这是一个非常常见的错误,请尝试组装您的jar,创建一个带有依赖项的uber jar。您可以使用jar tf*.jarcommands检查jar的内容,谢谢您的输入。我试图使用sbt assembly创建uber jar,但遇到了后续问题。程序集在执行过程中校准了丢失的内存,但我真不敢相信这就是问题所在。新员额: