再次学习 java 类的编译

做JAVA开发的都知道myeclipse, 我们在myeclipse中新建一个类,然后保存, 如何正常的话,那么在项目指定的目录(也就是项目的output目录)就会生成同名的class文件,

可是,我们都知道myeclipse中的类的编译的原理?

看起来很简单的东西, 其实不搞清楚的话, 也是会让自己吃大亏的!

所谓基础不牢固, 是很难成长的。 ———— 很大可能只是在泥潭中沉沦, 想想自己前几年的经历就知道了。

项目部署在 虚拟机的 tomcat上, tomcat启动的时候出现了错误

[ERROR] [08-15 18:46:17] net.jweb.listener.AppInitializerListener - 启动初始化异常:

java.lang.ClassCastException: org.springframework.beans.factory.BeanCreationException cannot be cast to org.springframework.web.cont

ext.WebApplicationContext

at net.jweb.listener.AppInitializerListener.contextInitialized(AppInitializerListener.java:91)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

at org.apache.catalina.core.StandardService.start(StandardService.java:525)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

[ERROR] [08-15 18:50:25] org.springframework.web.context.ContextLoader - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syncServiceImpl' defined in file [/usr/linka

pp/bin/tomcat-master/webapps/ROOT/WEB-INF/classes/net/jweb/services/impl/SyncServiceImpl.class]: Instantiation of bean failed; neste

d exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [net.jweb.services.impl.SyncSe

rviceImpl]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems:

The import org.apache.http.client.fluent cannot be resolved

The import org.apache.http.client.fluent cannot be resolved

The import com.alibaba cannot be resolved

Request cannot be resolved to a type

Request cannot be resolved

Response cannot be resolved to a type

JSONObject cannot be resolved to a type

JSONObject cannot be resolved

Request cannot be resolved to a type

Request cannot be resolved

Response cannot be resolved to a type

JSONObject cannot be resolved to a type

JSONObject cannot be resolved

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanF

actory.java:883)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBe

anFactory.java:839)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFact

ory.java:440)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.jav

a:409)

at java.security.AccessController.doPrivileged(Native Method)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactor

y.java:380)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)

at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

at org.apache.catalina.core.StandardService.start(StandardService.java:525)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

这个错误也见过不少了, compilation problems就是编译错误嘛。 我的第一直觉是少了jar。 研究了一会,发现了是少了fluent-hc-4.5.jar。 打开本地项目的lib目录, fluent-hc-4.5.jar 确实存在的!

是存在的, 但是没有加入项目的classpath, 也就是项目的 java build path —— libraies 。 加入后, 果然, 问题解决。

———— 等等, 其实呢, 远程项目的lib 目录也是有fluent-hc-4.5.jar, 那么为什么还是有这样的错误? 那是因为远程项目的net.jweb.services.impl.SyncServiceImpl 文件是有错误的! —— 虽然有class 文件,

但是那个class文件是错误的! SyncServiceImpl是配置的spring中的 服务, spring中的一个服务启动初始化出现异常, 那么spring 也启动不了了! 进而 tomcat也 启动不了了(这个当然,是跟项目代码有关的。 )

...

2016-8-15 19:03:30 org.apache.catalina.core.StandardContext start

严重: Error listenerStart

2016-8-15 19:03:30 org.apache.catalina.core.StandardContext start

严重: Context [] startup failed due to previous errors

[lk ] INFO [08-15 19:03:30] [main] com.log4ic.utils.support.DocViewerServiceListener.contextDestroyed(92) | 销毁DocViewer

Quartz Scheduler successful shutdown.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [] appears to have started a thread named [OfficeProcessThread-0] but has failed to stop it. This is very likely to create a memory leak.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [] appears to have started a thread named [process reaper] but has failed to stop it. This is very likely to create a memory leak.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [] appears to have started a thread named [MessageDispatcher] but has failed to stop it. This is very likely to create a memory leak.

2016-8-15 19:03:30 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap

严重: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@27b92195]) and a value of type [org.apache.cxf.bus.CXFBusImpl] (value [org.apache.cxf.bus.CXFBusImpl@381ebaf3]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

2016-8-15 19:03:31 org.apache.catalina.startup.HostConfig deployDescriptor

信息: Deploying configuration descriptor host-manager.xml

...

**再次, 将SyncServiceImpl.class 丢过去 重启就ok了!

不信,我们看看下面的:

将SyncServiceImpl的

import com.alibaba.fastjson.JSONObject

改成

import com.alibaba.fastjson.JSONOb6ject

也就是JSONObject 改成了 JSONOb6ject , JSONOb6ject 是不存在的。 这样, 编译将SyncServiceImpl.java 肯定是不成功的, 不信?

我们打开将SyncServiceImpl.class 看看:

再次学习 java 类的编译

看到了吧,竟然每个方法内部都是这样的:

throw new Error("Unresolved compilation problem: \n");**

再次, 将SyncServiceImpl.class 丢过去 重启出现错误:

[lk ] ERROR [08-15 19:03:28] [main] org.springframework.web.context.ContextLoader.initWebApplicationContext(215) | Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syncServiceImpl' defined in file [/usr/lk/bin/tomcat-master/webapps/ROOT/WEB-INF/classes/net/jweb/services/impl/SyncServiceImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [net.jweb.services.impl.SyncServiceImpl]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems:

The import com.alibaba.fastjson.JSONOb6ject cannot be resolved

JSONObject cannot be resolved to a type

JSONObject cannot be resolved

JSONObject cannot be resolved to a type

JSONObject cannot be resolved

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
上一篇:CSS非ASCII字符最佳实践


下一篇:python 全栈开发,Day52(关于DOM操作的相关案例,JS中的面向对象,定时器,BOM,client、offset、scroll系列)