部署maven項目問題

  1. 因爲原來項目與本地項目的環境不一致問題,誤將Maven Dependencies 刪除,從新update項目後未將jar導入tomcat,部署報錯: java

Caused by: java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger;
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2436)
	at java.lang.Class.getDeclaredFields(Class.java:1806)
	at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
	at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256)
	at org.apache.catalina.startup.WebAnnotationSet.loadApplicationFilterAnnotations(WebAnnotationSet.java:105)
	at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:64)
	at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:334)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:774)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5080)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
	... 24 more

解決方法以下:apache

  1. 右鍵項目,properties,Deployment Assembly:tomcat


  2. 發現沒有Maven Dependencies項,點擊Add,出現以下界:app

  3. 點擊Java Build Path Entris 會出現Maven Dependencies選項,添加進來便可。ui

  4. 再次運行項目,問題解決。spa

總結:Maven Dependencies裏面包含整個項目所需的jar包,部署到容器中時,必須將這些包,放到WEB-INF/lib 目錄下。
code

相關文章
相關標籤/搜索