Eclipse打开软件时报错:
!ENTRYorg.eclipse.e4.ui.workbench 4 0 2018-04-03 18:46:47.188
!MESSAGEFrameworkEvent ERROR
!STACK0
java.lang.NoClassDefFoundError:javax/annotation/PreDestroy
atorg.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:450)
atorg.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:156)
atorg.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:78)
atorg.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111)
atorg.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:74)
atorg.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:178)
atorg.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:99)
atorg.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:141)
atorg.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
atorg.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
atorg.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
atorg.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213)
atorg.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120)
atorg.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112)
atorg.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168)
atorg.eclipse.osgi.container.Module.publishEvent(Module.java:476)
atorg.eclipse.osgi.container.Module.doStop(Module.java:634)
atorg.eclipse.osgi.container.Module.stop(Module.java:498)
atorg.eclipse.osgi.container.SystemModule.stop(SystemModule.java:202)
atorg.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:165)
atjava.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException:javax.annotation.PreDestroy cannot be found byorg.eclipse.e4.core.di_1.6.100.v20170421-1418
atorg.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433)
atorg.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
atorg.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
atorg.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
atjava.base/java.lang.ClassLoader.loadClass(Unknown Source)
…21 more
上网搜查原因:JDK9版本不匹配,建议更换低版本JDK
网上给出的解决方法:在eclipse的启动的配置文件eclipse.ini文件末尾添加一行:–add-modules=ALL-SYSTEM
但是打开Eclipse时,依然报错……
依稀记得,以前自己配的JDK版本是1.8,怎么回事呢?
在CMD中,输入Java -version,显示:java version “9”,难道我配错了???
检查环境变量:鼠标右键点击“计算机”,依次点击属性、高级系统设置、环境变量,
变量名:JAVA_HOME
变量值:C:\Program Files\Java\jdk1.8.0_31
变量名:CLASSPATH
变量值:%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
变量名:Path
变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;C:\ProgramFiles\Java\jdk1.8.0_31\bin;
Java版本是1.8.0_31,没错呀,为啥Java-version,显示:java version “9”呢?
经高手指点:在CMD中输入javac -version,显示:Java -version,显示:javac 1.8.0_31。看到这里,似乎明白了点什么。
解释:
同时安装了jdk1.8.0_31和jre9,且PATH变量中,C:\WINDOWS\system32目录在%JAVA_HOME%\bin之前。在Windows命令行下执行命令时,先从当前目录搜素,然后按照PATH设置的路径依次查找命令,而JRE安装时会将java.exe安装到C:\WINDOWS\system32目录下,所以执行java -version命令时,查看的是jre的版本,而javac -version时查看的jdk的版本。
解决方法:
将%JAVA_HOME%\bin加在PATH变量的头,执行java -version和javac-version,均为1.8.0_31
注:
javac-version得到的是编译版本
java-version得到的运行版本