ClassNotFoundException with Guice 2.0
Asked Answered
D

5

7

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

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

The error is:

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 can be the problem?

Developing answered 12/8, 2009 at 14:38 Comment(0)
T
12

You have missed to include a dependency jar with the class org.aopalliance.intercept.MethodInterceptor in the classpath.

Transonic answered 12/8, 2009 at 15:6 Comment(1)
typical case of RTFM I guess. Thx!!Developing
H
6

as Boris Pavlović mentions in his answer, you're missing a jar. Specifically the aopalliance.jar file, which comes in the guice zip file

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

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

  • If you are running 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, typically you'll have some type of lib/ directory. Put your jar there, then right-click on the jar -> Build Path -> Add to Build Path
Heckle answered 12/8, 2009 at 15:26 Comment(0)
R
2

I run into this problem yesterday, the dependency is managed by Maven, so the aopalliance.jar is in classpath with no doubt.

Update jetty from version 6.1.10 to 6.1.26 fixed the problem.

The real problem here is the container does not support aopalliance.jar. I hope that will help someone there desperately looking for a solution.

Retaliation answered 8/12, 2010 at 2:48 Comment(1)
I'm using 6.1.26 and still getting the problem :(Shool
P
0

I run into this problem today. Actually the tomcat can not find the class in its lib. So just copy the aopalliance.jar into the lib folder in tomcat ,that's enough.

Presa answered 2/3, 2012 at 11:15 Comment(0)
C
-2

Adding the below jars works fine for me.
javax.inject.jar
guice-3.0-no_aop.jar

Collbaith answered 9/7, 2016 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.