user3772960 user3772960 - 5 months ago 13x
Java Question

Maven not installing dependency

I have the following (short)

for a Maven project. I added the
dependency, yet I do not see any of the classes for this dependency on in the
directory when I do a
maven clean package
. Furthermore, when I execute the JAR, I get an error (
java.lang.NoClassDefFoundError: com/google/common/collect/Iterables
). What am I forgetting to do?

<dependency> <!-- Spark dependency -->
<!-- -->


You won't see dependencies in target/classes, those are just used for compilation and taken from your $HOME/.m2/repository.

If you need to run the resulting jar you will need to either:

  1. Construct the full classpath with all the dependencies (jars that you use from the local maven repository $HOME/.m2/repository.
  2. Create an uberjar that will contain all the classes packaged into a single jar (you can use maven assembly plugin or shade plugin for that).

E.g. for assembly plugin you will need to add plugin to the plugins section:


And later execute maven with assembly:single, e.g:

mvn clean package assembly:single

The resulting jar will be target/java-page-rank-1.0-SNAPSHOT-jar-with-dependencies.jar.