title: Maven project building but cannot find classes at runtime
body: <p>I have this pom.xml file:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;suman&lt;/groupId&gt;
      &lt;artifactId&gt;suman&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;suman&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;2.8.5&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
  
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>and I have this main file:</p>
  
  <pre><code>package suman;
  
  import java.net.*;
  import java.io.*;
  import com.google.code.gson.*;  // can't find this lib
  
  
  public class App {
      public static void main(String[] args) {
  
          Gson gson = new Gson();
          gson.toJson(1);            
  
      }
  }
  </code></pre>
  
  <p>and then I install with:</p>
  
  <pre><code>$ mvn install -DskipTests
  </code></pre>
  
  <p>and I get this <em>compile error</em>:</p>
  
  <blockquote>
    <p>[ERROR] Failed to execute goal
    org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
    (default-compile) on project suman: Compilation failure: Compilation
    failure:  [ERROR]
    /home/oleg/codes/oresoftware/oredoc/test/builds/java/gson/src/main/java/suman/App.java:[5,1]
    package com.google.code.gson does not exist [ERROR]
    /home/oleg/codes/oresoftware/oredoc/test/builds/java/gson/src/main/java/suman/App.java:[17,9]
    cannot find symbol [ERROR]   symbol:   class Gson [ERROR]   location:
    class suman.App [ERROR]
    /home/oleg/codes/oresoftware/oredoc/test/builds/java/gson/src/main/java/suman/App.java:[17,25]
    cannot find symbol [ERROR]   symbol:   class Gson [ERROR]   location:
    class suman.App</p>
  </blockquote>
  
  <p>Does anyone know why it can't find the gson libraries? seems really weird.</p>
  
  <p>Ok so if I change it to:</p>
  
  <pre><code>import com.google.gson.*;
  </code></pre>
  
  <p>then it compiles, but then if I run it with <code>java -jar</code>, I get this <em>runtime error</em>:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NoClassDefFoundError:
    com/google/gson/Gson
            at suman.App.main(App.java:17) Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
            ... 1 more</p>
  </blockquote>