Jenkins 啟動時發生錯誤 java.lang.NoClassDefFoundError: net/sf/ezmorph/MorpherRegistry

  • 355
  • 0

簡答: 刪除 jenkins 下的 war 資料夾,在重啟 jenkins

今天在跑 unit test 的 job 時,發現早上還會過的 job 下午在某個 branch 跑就失敗,之後換個 branch 也還是失敗,把 jenkins 服務停止再重啟一次,重啟後沒多久就又莫名其妙的又停止了,就再也起不來了...

查了一下 jenkins 目錄下的 jenkins.err.log,看到是 java 找不到 net/sf/ezmorph/MorpherRegistry 這個 class

017 3:31:29 PM winstone.Logger logInternal
INFO: Beginning extraction from war file
Dec 01, 2017 3:31:29 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-winstone-2.9
Dec 01, 2017 3:31:30 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
Dec 01, 2017 3:31:31 PM hudson.WebAppMain contextInitialized
SEVERE: Failed to initialize Jenkins
java.lang.NoClassDefFoundError: net/sf/ezmorph/MorpherRegistry
	at net.sf.json.util.JSONUtils.<clinit>(JSONUtils.java:61)
	at hudson.security.Permission.<init>(Permission.java:152)
	at hudson.security.Permission.<init>(Permission.java:168)
	at hudson.security.Permission.<init>(Permission.java:187)
	at hudson.security.Permission.<clinit>(Permission.java:311)
	at jenkins.model.Jenkins.<clinit>(Jenkins.java:4656)
	at hudson.WebAppMain.installLogger(WebAppMain.java:315)
	at hudson.WebAppMain.contextInitialized(WebAppMain.java:120)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
	at org.eclipse.jetty.server.Server.doStart(Server.java:282)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at winstone.Launcher.<init>(Launcher.java:156)
	at winstone.Launcher.main(Launcher.java:356)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at Main._main(Main.java:307)
	at Main.main(Main.java:98)
Caused by: java.lang.ClassNotFoundException: net.sf.ezmorph.MorpherRegistry
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
	... 27 more

Google 了一下,MorpherRegistry 這個 Class 是包含在 json-lib 這個組件裡面,到 jenkins 目錄中搜尋了一下,發現有 .\war\WEB-INF\lib\json-lib-2.4-jenkins-2.jar 這個檔案,不過修改日期跟我安裝 jenkins 的日期不太一樣,懷疑這個檔案有被改過。查了一下 war 這個資料夾的用處:

This directory contains the expanded web application. When you start Jenkins as a stand-alone application, it will extract the web application into this directory.

 

原來是 jenkins 的 web app 的跟目錄,執行 jenkins 時,它會自動再生出一份,所以就試試看把它砍了,再次重啟 jenkins 就正常了~