Maven project building but cannot find classes at runtime












2














I have this pom.xml file:



<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">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>


and I have this main file:



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);

}
}


and then I install with:



$ mvn install -DskipTests


and I get this compile error:




[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




Does anyone know why it can't find the gson libraries? seems really weird.



Ok so if I change it to:



import com.google.gson.*;


then it compiles, but then if I run it with java -jar, I get this runtime error:




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











share|improve this question
























  • ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
    – rakim
    Nov 20 at 22:09










  • try maven clean build
    – Deadpool
    Nov 20 at 22:09










  • @Deadpool see my comment right above yours, do you get it?
    – rakim
    Nov 20 at 22:09










  • okay, first thing why do you need com.google.gson.* just try importing required import statements
    – Deadpool
    Nov 20 at 22:13








  • 1




    Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
    – Sean Bright
    Nov 20 at 22:21
















2














I have this pom.xml file:



<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">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>


and I have this main file:



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);

}
}


and then I install with:



$ mvn install -DskipTests


and I get this compile error:




[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




Does anyone know why it can't find the gson libraries? seems really weird.



Ok so if I change it to:



import com.google.gson.*;


then it compiles, but then if I run it with java -jar, I get this runtime error:




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











share|improve this question
























  • ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
    – rakim
    Nov 20 at 22:09










  • try maven clean build
    – Deadpool
    Nov 20 at 22:09










  • @Deadpool see my comment right above yours, do you get it?
    – rakim
    Nov 20 at 22:09










  • okay, first thing why do you need com.google.gson.* just try importing required import statements
    – Deadpool
    Nov 20 at 22:13








  • 1




    Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
    – Sean Bright
    Nov 20 at 22:21














2












2








2


3





I have this pom.xml file:



<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">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>


and I have this main file:



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);

}
}


and then I install with:



$ mvn install -DskipTests


and I get this compile error:




[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




Does anyone know why it can't find the gson libraries? seems really weird.



Ok so if I change it to:



import com.google.gson.*;


then it compiles, but then if I run it with java -jar, I get this runtime error:




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











share|improve this question















I have this pom.xml file:



<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">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>


and I have this main file:



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);

}
}


and then I install with:



$ mvn install -DskipTests


and I get this compile error:




[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




Does anyone know why it can't find the gson libraries? seems really weird.



Ok so if I change it to:



import com.google.gson.*;


then it compiles, but then if I run it with java -jar, I get this runtime error:




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








java maven gson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 22:34

























asked Nov 20 at 22:06









rakim

1487




1487












  • ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
    – rakim
    Nov 20 at 22:09










  • try maven clean build
    – Deadpool
    Nov 20 at 22:09










  • @Deadpool see my comment right above yours, do you get it?
    – rakim
    Nov 20 at 22:09










  • okay, first thing why do you need com.google.gson.* just try importing required import statements
    – Deadpool
    Nov 20 at 22:13








  • 1




    Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
    – Sean Bright
    Nov 20 at 22:21


















  • ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
    – rakim
    Nov 20 at 22:09










  • try maven clean build
    – Deadpool
    Nov 20 at 22:09










  • @Deadpool see my comment right above yours, do you get it?
    – rakim
    Nov 20 at 22:09










  • okay, first thing why do you need com.google.gson.* just try importing required import statements
    – Deadpool
    Nov 20 at 22:13








  • 1




    Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
    – Sean Bright
    Nov 20 at 22:21
















ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
– rakim
Nov 20 at 22:09




ok so if I mport this instead com.google.gson.* of this com.google.code.gson.* it works, but why is that?
– rakim
Nov 20 at 22:09












try maven clean build
– Deadpool
Nov 20 at 22:09




try maven clean build
– Deadpool
Nov 20 at 22:09












@Deadpool see my comment right above yours, do you get it?
– rakim
Nov 20 at 22:09




@Deadpool see my comment right above yours, do you get it?
– rakim
Nov 20 at 22:09












okay, first thing why do you need com.google.gson.* just try importing required import statements
– Deadpool
Nov 20 at 22:13






okay, first thing why do you need com.google.gson.* just try importing required import statements
– Deadpool
Nov 20 at 22:13






1




1




Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
– Sean Bright
Nov 20 at 22:21




Java programs have two classpaths - one at compile time and another at runtime. You need to include the gson library on your classpath at runtime as well.
– Sean Bright
Nov 20 at 22:21












2 Answers
2






active

oldest

votes


















2














Most likely your local Maven repository does not have jar file for:



    <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>


try to look down from ~/.m2/repository/com/google/code/gson/gson/2.8.5 directory.



If there is no jar file like gson-2.8.5.jar - simple step delete whole directory.



With next build it will force Maven to try to download that artifact from your defined remote repositories and you will see how it passed.



Either it will download and all will be fine or it will not.



If not - then check your settings.xml (or pom file) about repository from where it can be downloaded ( at least in Maven repository listing (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) it is https://mvnrepository.com/artifact/com.google.code.gson/gson



If you have that repository defined and you are behind corporate proxy - check your proxy settings for Maven in settings.xml



BTW: at run time you must have all needed jar files in class path as long as you build jar (not war or ear). As alternative with Maven you can build "fat jar" and all classes from all dependencies will be there, but be ready it will be a really big fat jar. :-)






share|improve this answer





























    2














    Ok so I was building my project with



    $ mvn install -DskipTests


    and then running it with:



    $ java -cp target/suman-1.0-SNAPSHOT.jar suman.App


    but instead I should use mvn to run it, like so:



    $ mvn exec:java -Dexec.mainClass="suman.App"


    now it has the right jar files in the classpath. using the plain java command, it didn't know where to find the com.google.code.gson jar file.



    As an aside, I don't know why this fails to compile:



    import com.google.code.gson.*;


    but this succeeds:



    import com.google.gson.*;


    according to the pom.xml file, I would think the former not that latter would be correct.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402318%2fmaven-project-building-but-cannot-find-classes-at-runtime%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Most likely your local Maven repository does not have jar file for:



          <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.5</version>
      </dependency>


      try to look down from ~/.m2/repository/com/google/code/gson/gson/2.8.5 directory.



      If there is no jar file like gson-2.8.5.jar - simple step delete whole directory.



      With next build it will force Maven to try to download that artifact from your defined remote repositories and you will see how it passed.



      Either it will download and all will be fine or it will not.



      If not - then check your settings.xml (or pom file) about repository from where it can be downloaded ( at least in Maven repository listing (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) it is https://mvnrepository.com/artifact/com.google.code.gson/gson



      If you have that repository defined and you are behind corporate proxy - check your proxy settings for Maven in settings.xml



      BTW: at run time you must have all needed jar files in class path as long as you build jar (not war or ear). As alternative with Maven you can build "fat jar" and all classes from all dependencies will be there, but be ready it will be a really big fat jar. :-)






      share|improve this answer


























        2














        Most likely your local Maven repository does not have jar file for:



            <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
        </dependency>


        try to look down from ~/.m2/repository/com/google/code/gson/gson/2.8.5 directory.



        If there is no jar file like gson-2.8.5.jar - simple step delete whole directory.



        With next build it will force Maven to try to download that artifact from your defined remote repositories and you will see how it passed.



        Either it will download and all will be fine or it will not.



        If not - then check your settings.xml (or pom file) about repository from where it can be downloaded ( at least in Maven repository listing (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) it is https://mvnrepository.com/artifact/com.google.code.gson/gson



        If you have that repository defined and you are behind corporate proxy - check your proxy settings for Maven in settings.xml



        BTW: at run time you must have all needed jar files in class path as long as you build jar (not war or ear). As alternative with Maven you can build "fat jar" and all classes from all dependencies will be there, but be ready it will be a really big fat jar. :-)






        share|improve this answer
























          2












          2








          2






          Most likely your local Maven repository does not have jar file for:



              <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.8.5</version>
          </dependency>


          try to look down from ~/.m2/repository/com/google/code/gson/gson/2.8.5 directory.



          If there is no jar file like gson-2.8.5.jar - simple step delete whole directory.



          With next build it will force Maven to try to download that artifact from your defined remote repositories and you will see how it passed.



          Either it will download and all will be fine or it will not.



          If not - then check your settings.xml (or pom file) about repository from where it can be downloaded ( at least in Maven repository listing (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) it is https://mvnrepository.com/artifact/com.google.code.gson/gson



          If you have that repository defined and you are behind corporate proxy - check your proxy settings for Maven in settings.xml



          BTW: at run time you must have all needed jar files in class path as long as you build jar (not war or ear). As alternative with Maven you can build "fat jar" and all classes from all dependencies will be there, but be ready it will be a really big fat jar. :-)






          share|improve this answer












          Most likely your local Maven repository does not have jar file for:



              <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.8.5</version>
          </dependency>


          try to look down from ~/.m2/repository/com/google/code/gson/gson/2.8.5 directory.



          If there is no jar file like gson-2.8.5.jar - simple step delete whole directory.



          With next build it will force Maven to try to download that artifact from your defined remote repositories and you will see how it passed.



          Either it will download and all will be fine or it will not.



          If not - then check your settings.xml (or pom file) about repository from where it can be downloaded ( at least in Maven repository listing (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) it is https://mvnrepository.com/artifact/com.google.code.gson/gson



          If you have that repository defined and you are behind corporate proxy - check your proxy settings for Maven in settings.xml



          BTW: at run time you must have all needed jar files in class path as long as you build jar (not war or ear). As alternative with Maven you can build "fat jar" and all classes from all dependencies will be there, but be ready it will be a really big fat jar. :-)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 22:26









          Vadim

          3,3082622




          3,3082622

























              2














              Ok so I was building my project with



              $ mvn install -DskipTests


              and then running it with:



              $ java -cp target/suman-1.0-SNAPSHOT.jar suman.App


              but instead I should use mvn to run it, like so:



              $ mvn exec:java -Dexec.mainClass="suman.App"


              now it has the right jar files in the classpath. using the plain java command, it didn't know where to find the com.google.code.gson jar file.



              As an aside, I don't know why this fails to compile:



              import com.google.code.gson.*;


              but this succeeds:



              import com.google.gson.*;


              according to the pom.xml file, I would think the former not that latter would be correct.






              share|improve this answer


























                2














                Ok so I was building my project with



                $ mvn install -DskipTests


                and then running it with:



                $ java -cp target/suman-1.0-SNAPSHOT.jar suman.App


                but instead I should use mvn to run it, like so:



                $ mvn exec:java -Dexec.mainClass="suman.App"


                now it has the right jar files in the classpath. using the plain java command, it didn't know where to find the com.google.code.gson jar file.



                As an aside, I don't know why this fails to compile:



                import com.google.code.gson.*;


                but this succeeds:



                import com.google.gson.*;


                according to the pom.xml file, I would think the former not that latter would be correct.






                share|improve this answer
























                  2












                  2








                  2






                  Ok so I was building my project with



                  $ mvn install -DskipTests


                  and then running it with:



                  $ java -cp target/suman-1.0-SNAPSHOT.jar suman.App


                  but instead I should use mvn to run it, like so:



                  $ mvn exec:java -Dexec.mainClass="suman.App"


                  now it has the right jar files in the classpath. using the plain java command, it didn't know where to find the com.google.code.gson jar file.



                  As an aside, I don't know why this fails to compile:



                  import com.google.code.gson.*;


                  but this succeeds:



                  import com.google.gson.*;


                  according to the pom.xml file, I would think the former not that latter would be correct.






                  share|improve this answer












                  Ok so I was building my project with



                  $ mvn install -DskipTests


                  and then running it with:



                  $ java -cp target/suman-1.0-SNAPSHOT.jar suman.App


                  but instead I should use mvn to run it, like so:



                  $ mvn exec:java -Dexec.mainClass="suman.App"


                  now it has the right jar files in the classpath. using the plain java command, it didn't know where to find the com.google.code.gson jar file.



                  As an aside, I don't know why this fails to compile:



                  import com.google.code.gson.*;


                  but this succeeds:



                  import com.google.gson.*;


                  according to the pom.xml file, I would think the former not that latter would be correct.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 22:31









                  rakim

                  1487




                  1487






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402318%2fmaven-project-building-but-cannot-find-classes-at-runtime%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen