java.lang.NoClassDefFoundError: com/google/inject/Module using Guice

Tags: , ,

I am trying to use the DI mechanism provided by Google, but when I run my application, I am getting the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at challenge.App.main(
Caused by: java.lang.ClassNotFoundException:
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 1 more

The pom.xml file looks like:


And the code where I am using it looks like:

    Injector injector = Guice.createInjector(new DependenciesModule());
    IndexerController indexer = injector.getInstance(IndexerController.class);

And I have imported and

I have been checking for several places but I cannot see any relevant solution for this problems, I would appreciate a lot any glue.


This appears like the usual issue with Maven in that at runtime, the dependency classes (e.g. the Guice classes) are not available to the JVM.

The easiest solution is to use explicit classpath specification while running your app:

java -cp 

(this is all on one line, split for better viewing).

The other solution is to use Maven Shade Plugin which facilitates the creation of the executable JAR which you can simply run as java -jar uber.jar.

Source: stackoverflow