title: Docker to Run Small Java Class: Could Not Find Or Load Main Class (Even Though It Exists)
body: <p>I realize that this question may already have been asked, but in my research I can't find an answer.  I'm probably making a simple mistake.</p>
  
  <p>I would like to run a Java class locally with Docker, inside a container.  Below is my Dockerfile:</p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM maven:3.5.2-jdk-8
  
  COPY src /src
  
  RUN javac src/java/com/Main.java
  CMD java src/java/com/Main
  </code></pre>
  
  <p>I then run these commands in order:</p>
  
  <pre><code>docker build -t my_image_6_26_19:latest .
  docker run -it my_image_6_26_19:latest
  </code></pre>
  
  <p>The <code>build</code> command runs fine, but the <code>run</code> command throws the following error:</p>
  
  <pre><code>Error: Could not find or load main class src.java.com.Main
  </code></pre>
  
  <p>I have reviewed the following questions on SO, but no answers seem to work (or maybe I didn't catch the solution): </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/49922516/buildning-docker-image-from-dockerfile-with-maven-error-could-not-find-or-lo">Buildning docker image from Dockerfile with maven - Error: &quot;Could not find or load main class&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/35291076/dockerfile-to-run-a-java-program">DockerFile to run a java program</a></li>
  <li><a href="https://stackoverflow.com/questions/54144292/docker-error-could-not-find-or-load-main-class-main-main">Docker Error: Could not find or load Main class Main.Main</a></li>
  </ul>
  
  <p>When I build the container, through some debugging (<code>RUN ls /src/java/com</code>) I can see that a file <code>Main.class</code> is being created.  I'm not sure why that file can't be found.  Additionally, I have tried changing the last line of my Dockerfile to <code>CMD java src/java/com/Main.class</code>, but no luck.</p>