MyEclipse环境的项目改为在Eclipse中运行爬坑记【我】

 

 

 

新检出一个web项目,同事都是运行在MyEclipse中的,我用Eclipse启动,

 

1、首先是许多jar包报错:

处理方法为 remove掉,然后 选 WEB-INF 下的所有 jar 重新添加进去。

 

2、MyEclipse 中自带 JavaEE5 library jar包合集,而Eclipse中没有,项目中有用到,解决方法

从同事的 MyEclipse 安装目录下把  EE_5 目录拷过来,主要是有下面这4个jar包:

然后,添加到项目中,可以建一个用户目录:

 

 

这样就建好了,如图:

但是这时,项目启动,还是不会把这些jar引入到项目中,还需要如下配置:

添加完是如下效果:

 

这样就把Javaee5的相关jar包彻底引入到项目中了。

 

3、启动项目,报如下异常:

 

典型异常信息: URL [jar:file:/C:/Program%20Files%20(x86)/Java/jre6/lib/ext/jfxrt.jar!/com/sun/glass/ui/Accessible.class

 

全部异常信息如下:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [applicationContext-service.xml]
Offending resource: class path resource [config/spring/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Program%20Files%20(x86)/Java/jre6/lib/ext/jfxrt.jar!/com/sun/glass/ui/Accessible.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 3805021
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:271)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:196)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:181)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:530)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:444)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Program%20Files%20(x86)/Java/jre6/lib/ext/jfxrt.jar!/com/sun/glass/ui/Accessible.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 3805021
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:261)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1423)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1413)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:255)
    ... 29 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3805021
    at org.springframework.asm.ClassReader.readInt(Unknown Source)
    at org.springframework.asm.ClassReader.accept(Unknown Source)
    at org.springframework.asm.ClassReader.accept(Unknown Source)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:59)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:237)
    ... 42 more
com.cthq.crm.webservice.task.BussinessTask@834e7
2019-08-12 15:45:26,084 INFO  [Timer-1] com.jtcrm.resource.framework.taskmanager.CacheFlushLoigc.processLogic(CacheFlushLoigc.java:28)  {} -   processLogic start!!!
2019-08-12 15:45:26,097 INFO  [Timer-1] com.jtcrm.resource.framework.taskmanager.CacheFlushLoigc.processLogic(CacheFlushLoigc.java:33)  {} -  0
2019-08-12 15:45:26,097 INFO  [Timer-1] com.jtcrm.resource.framework.taskmanager.CacheFlushLoigc.processLogic(CacheFlushLoigc.java:72)  {} -   processLogic end!!!
2019-8-12 15:45:26 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
2019-8-12 15:45:26 org.apache.catalina.core.StandardContext startInternal
严重: Context [/CRMResource] startup failed due to previous errors
2019-8-12 15:45:26 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2019-8-12 15:45:26 org.apache.catalina.core.StandardContext listenerStop
严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1078)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1052)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1000)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:548)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5014)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5659)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

 

 不管是 使用 jdk 1.8,还是jdk 1.6 都是报上面的异常。

 最终参考下面的博文,

org.springframework.asm.ClassReader.(Unknown Source) 解决方案

此类问题一般在 spring版本 与 jdk版本不匹配的情况下会出现。

匹配规则:

spring3 + java7

spring4 + java8

解决方案:

 

1:检查项目的jdk编译版本 :右键项目,进入项目偏好设置,找到 java Compiler ,将jdk修改到你对应的spring版本

2:检查tomcat的jre版本:以eclipse为例:打开eclipse的偏好设置,搜索 server ,找到 Runtime Environments 找到你加载进来的tomcat 点击edit,将jre修改为对应你spring的版本。

到此问题应该就能得到解决。

 

 

发现本地项目用的Spring是3.1:

 

 将jdk改为1.7后,故障排除【奇怪的是,同时用MyEclipse,用的其自带1.6环境运行项目居然不报错】。

 

 

Eclipse切换jdk的方法:

一、Eclipse中整体添加多个jdk

 

 

这里只要选中一个包含 jdk 内容的目录即可,这个目录中的jdk不用真的安装在电脑里面,只要有这个文件夹就行了。

这样一个新的 jdk环境就添加到Eclipse中了,一个Eclipse中可以添加多个JDK环境。

 

二、项目的JDK主要有两个部分

1编译环境:

项目右键

 

2、是运行项目的Tomcat的jdk环境:

 

posted @ 2019-08-12 16:31  戈博折刀  阅读(537)  评论(0编辑  收藏  举报