0
我正在使用Google Guice編寫程序,但我得到了異常!爲了測試我寫了一個小程序,但它不工作!Google Guice找不到類
有所有類:
Main.java:
import com.google.inject.Guice;
public class Main {
public static void main(String[] args) {
ITest test = Guice.createInjector(new TestModule()).getInstance(ITest.class);
}
}
ITest.java:
public interface ITest {
}
Test.java:
public class Test implements ITest {
}
TestModule.java:
import com.google.inject.AbstractModule;
public class TestModule extends AbstractModule {
@Override
protected void configure() {
bind(ITest.class).to(Test.class);
}
}
依賴於的pom.xml:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
抗辯ñ堆棧跟蹤:
"C:\Program Files\Java\jdk1.8.0_101\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=D:\Rostislav\IDEs\IntelliJ IDEA Community Edition 2016.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar;D:\Rostislav\Projects\OSLoader\OSLoaderServer\target\classes;C:\Documents and Settings\Администратор\.m2\repository\org\xerial\sqlite-jdbc\3.8.11.2\sqlite-jdbc-3.8.11.2.jar;C:\Documents and Settings\Администратор\.m2\repository\com\netflix\rxjava\rxjava-core\0.20.7\rxjava-core-0.20.7.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-core\1.1.4.Final\weld-core-1.1.4.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\enterprise\cdi-api\1.0-SP4\cdi-api-1.0-SP4.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-api\1.1.Final\weld-api-1.1.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-spi\1.1.Final\weld-spi-1.1.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\annotation\jsr250-api\1.0\jsr250-api-1.0.jar;C:\Documents and Settings\Администратор\.m2\repository\org\javassist\javassist\3.14.0-GA\javassist-3.14.0-GA.jar;C:\Documents and Settings\Администратор\.m2\repository\com\google\guava\guava\r06\guava-r06.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\spec\javax\interceptor\jboss-interceptors-api_1.1_spec\1.0.0.Beta1\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\interceptor\jboss-interceptor-spi\2.0.0.CR1\jboss-interceptor-spi-2.0.0.CR1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\interceptor\jboss-interceptor-core\2.0.0.CR1\jboss-interceptor-core-2.0.0.CR1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\slf4j\slf4j-ext\1.5.10\slf4j-ext-1.5.10.jar;C:\Documents and Settings\Администратор\.m2\repository\ch\qos\cal10n\cal10n-api\0.7.2\cal10n-api-0.7.2.jar;C:\Documents and Settings\Администратор\.m2\repository\org\slf4j\slf4j-api\1.5.10\slf4j-api-1.5.10.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-build-config\1.1.4.Final\weld-build-config-1.1.4.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\org\json\json\20160212\json-20160212.jar;C:\Documents and Settings\Администратор\.m2\repository\com\google\inject\guice\4.0\guice-4.0.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Documents and Settings\Администратор\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Documents and Settings\Администратор\.m2\repository\com\j256\ormlite\ormlite-core\4.47\ormlite-core-4.47.jar;C:\Documents and Settings\Администратор\.m2\repository\com\j256\ormlite\ormlite-jdbc\4.47\ormlite-jdbc-4.47.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\Rostislav\IDEs\IntelliJ IDEA Community Edition 2016.2.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.dugin.rostislav.image.Main
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener
at com.google.inject.internal.InheritingState.<init>(InheritingState.java:67)
at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:209)
at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:115)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.dugin.rostislav.image.Main.main(Main.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.RemovalListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Picked up _JAVA_OPTIONS: -Xmx512M
Process finished with exit code 1
爲什麼我得到的異常,以及如何解決它?
程序開始自己,當我開始IDEA ... :)) – bukashka101