Class NotFoundException with Guice 2.0

The code below generates an error using Guice 2.0. Guice 1.0 is fine. JDK is an update for Java 6.

public class App { public static void main(String[] args) { Guice.createInjector(new AbstractModule() { @Override protected void configure() { // just testing } }); } } 

Mistake:

 Exception in thread "main" java.lang.NoClassDefFoundError: [Lorg/aopalliance/intercept/MethodInterceptor; at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) at java.lang.Class.getDeclaredMethods(Class.java:1791) at com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:78) at com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:70) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:232) at com.google.inject.spi.Elements.getElements(Elements.java:101) at com.google.inject.InjectorShell$Builder.build(InjectorShell.java:135) at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:102) at com.google.inject.Guice.createInjector(Guice.java:92) at com.google.inject.Guice.createInjector(Guice.java:69) at com.google.inject.Guice.createInjector(Guice.java:59) at App.main(App.java:6) Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 14 more 

What could be the problem?

+6
java classnotfoundexception guice
source share
5 answers

You missed the inclusion of the dependency byte with the class org.aopalliance.intercept.MethodInterceptor in the classpath.

+11
source share

as Boris Pavlovich mentions in his answer that you do not have a jug. In particular, the aopalliance.jar file, which is included in the list of zip file

Alternatively, you can try using guice-2.0-no_aop.jar , but I'm not sure if this will work.

Adding this file to the classpath depends on which tool you use to run your java code.

  • If you run java from the command line:
 windows: java -cp aopalliance.jar;guice-2.0.jar;other_jars.jar YourMainClass *nix: java -cp aopalliance.jar:guice-2.0.jar:other_jars.jar YourMainClass 
  • If you are running java from Eclipse, you will usually have some type of lib /. Put your jar there, then right-click on the jar → Assembly Path → Add to Assembly Path
+6
source share

I ran into this problem yesterday, the dependency is managed by Maven, so aopalliance.jar is in the classpath without any doubt.

Updating the berth from version 6.1.10 to 6.1.26 fixes the problem.

The real problem is that the container does not support aopalliance.jar. Hope this helps someone desperately find a solution.

+1
source share

I ran into this problem today. In fact, tomcat cannot find the class in its library. So just copy the aopalliance.jar file to the lib folder in tomcat, which is enough.

0
source share

Adding bottom cans is great for me.
javax.inject.jar
Guice-3.0-no_aop.jar

-2
source share

All Articles