Solution for java.lang.NoClassDefFoundError: com/google/inject/Module
Ever run a maven build or tried debugging a program or JUnit test only to find the below error:
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError:
com/google/inject/Module BeanDefinitionValueResolver.resolveReference com/google/inject/module
Read on for steps to fix the issue.




Ever run a maven build or tried debugging a program or JUnit test only to find the below error:
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError:
com/google/inject/Module BeanDefinitionValueResolver.resolveReference com/google/inject/module

Above error can happen when loading the spring application context. If it happens during a maven build, it seems like a bug in maven. You can add the below dependency section to the maven pom.xml file so that the required jar gets added to your local repository.

<dependency>
<groupid>com.google.inject</groupid>
<artifactid>guice</artifactid>
<version>2.0</version>
</dependency>

The version above might differ based on your local configuration. But in general, adding this dependency section to the pom.xml allows maven to add the related jar to your repository. You can use https://repository.sonatype.org/index.htmlto look up the maven snippet as it applies for your case. Generally, once the related jar gets downloaded we can remove the dependency as maven seems to understand what needs to be done after this.

If the problem happened on the other hand while running/debugging a program in IntelliJ or Eclipse, then you might want to add the guice-2.0.jar to your class path to resolve the issue.