java muki_再次学习 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 看看:
看到了吧,竟然每個方法內部都是這樣的:
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)
總結
以上是生活随笔為你收集整理的java muki_再次学习 java 类的编译的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NASA 顶级程序员是如何编程的?这里有
- 下一篇: Win32字符串处理函数