title: how to run first example of Apache Flink
body: <p>I am trying to run the first example from the oreilly book "Stream Processing with Apache Flink"  and from the flink project.  Each gives different errors</p>
  
  <p>Example from the book gies NoClassDefFound error
  Example from flink project gives java.net.ConnectException: Connection refused (Connection refused)  but does create a flink job, see screenshot.</p>
  
  <p>Detail below</p>
  
  <p><strong>Book example</strong></p>
  
  <blockquote>
    <p>java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError:scala/runtime/java8/JFunction1$mcVI$sp
    at io.github.streamingwithflink.chapter1.AverageSensorReadings$$anon$3.createSerializer(AverageSensorReadings.scala:50)</p>
  </blockquote>
  
  <p>The instructions from the book are:</p>
  
  <ol>
  <li><p>download <a href="https://archive.apache.org/dist/flink/flink-1.7.1/flink-1.7.1-bin-scala_2.12.tgz" rel="nofollow noreferrer">flink-1.7.1-bin-scala_2.12.tgz</a></p></li>
  <li><p>extract</p></li>
  <li>start cluster ./bin/start-cluster.sh</li>
  <li>open flink's web UI <a href="http://localhost:8081" rel="nofollow noreferrer">http://localhost:8081</a></li>
  </ol>
  
  <p>this all works fine</p>
  
  <ol start="5">
  <li>Download the <a href="https://github.com/streaming-with-flink/examples/blob/master/download/examples-scala.jar" rel="nofollow noreferrer">jar file</a> that includes examples in this book</li>
  <li>run example</li>
  </ol>
  
  <pre><code>./bin/flink run \
    -c io.github.streamingwithflink.chapter1.AverageSensorReadings \
    examples-scala.jar
  </code></pre>
  
  <p>It seems that the class is not found from error message at the top of this post.</p>
  
  <p>I put the jar in the same directory I am running the command</p>
  
  <pre><code>java -version
  openjdk version "1.8.0_242"
  OpenJDK Runtime Environment (Zulu 8.44.0.9-CA-macosx) (build 1.8.0_242-b20)
  OpenJDK 64-Bit Server VM (Zulu 8.44.0.9-CA-macosx) (build 25.242-b20, mixed mode)
  </code></pre>
  
  <p>I also tried compiling the jar myself with the same error.</p>
  
  <p><code>https://github.com/streaming-with-flink/examples-scala.git</code></p>
  
  <p>and</p>
  
  <p><code>mvn clean build</code></p>
  
  <p>error is the same.</p>
  
  <p><strong>Flink project tutorial</strong></p>
  
  <p>running the <a href="https://ci.apache.org/projects/flink/flink-docs-stable/getting-started/tutorials/local_setup.html" rel="nofollow noreferrer">SocketWindowWordCount</a></p>
  
  <p><code>./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000</code></p>
  
  <p>I get a job but it fails</p>
  
  <p>gives <code>java.net.ConnectException: Connection refused (Connection refused)</code></p>
  
  <p><a href="https://i.stack.imgur.com/7At0Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7At0Q.png" alt="enter image description here"></a>
  It is not clear to me what connection is refused.  I tried different ports with no change.</p>
  
  <p>How can I run flink code successfully?</p>