在Jetty中部署Jenkins遇到的問題

1. Jetty 9.0.3 啓動時的錯誤:javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@kvm-guest jetty-9.0.3]# java -jar start.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/start/Main : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:634) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) at java.net.URLClassLoader.access$000(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:212) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: org.eclipse.jetty.start.Main. Program will exit.

緣由:Jetty 9 須要 JVM 1.7 的支持(我原來的JVM是1.6) 
解決方案:使用Java 1.7便可。html

2. 將jenkns.war複製到webapp目錄後,啓動Jetty,但jenkins訪問出錯,HTTP ERROR 503。 
啓動和關閉Jetty的命令爲:java

1
2
3
[root@kvm-guest jetty-9.0.3]# java -jar start.jar -DSTOP.PORT=8881 -DSTOP.KEY=magic --daemon &   [root@kvm-guest jetty-9.0.3]# java -jar start.jar -DSTOP.PORT=8881 -DSTOP.KEY=magic --stop

在瀏覽器中訪問時,遇到的錯誤信息以下:web

1
2
3
4
5
HTTP ERROR: 503 Problem accessing /jenkins/. Reason: Service Unavailable ------------ Powered by Jetty

查看Jetty的log中,能夠看到以下的錯誤信息:瀏覽器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2013-05-21 14:33:31.265:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41: java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41 java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41 at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67) at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131) at org.eclipse.jetty.security.SecurityHandler.doStart(SecurityHandler.java:375) at org.eclipse.jetty.security.ConstraintSecurityHandler.doStart(ConstraintSecurityHandler.java:457) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) ................... 2013-05-21 14:33:31.267:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.session.SessionHandler@5b5e91e5: java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41 java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41 at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67) at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131) ................... 2013-05-21 14:33:31.268:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@729b9707{/jenkins,file:/tmp/jetty-0.0.0.0-8080-jenkins.war-_jenkins-any-/webapp/,STARTING}{/root/jetty-9.0.3/webapps.demo/jenkins.war} java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41 at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67) at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131) at org.eclipse.jetty.security.SecurityHandler.doStart(SecurityHandler.java:375) at org.eclipse.jetty.security.ConstraintSecurityHandler.doStart(ConstraintSecurityHandler.java:457) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)

緣由:Jetty 8.1.0以後對安全性有了一些要求,須要顯示註明安全域(security realm)。 
解決方法:編輯(或新建) webapps/jenkins.xml 文件,添加以下配置。安全

1
2
3
4
5
6
7
8
9
10
11
12
13
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/jenkins</Set> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/jenkins.war</Set> <Get name="securityHandler"> <Set name="loginService"> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">Jenkins Realm</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> </New> </Set> </Get>   </Configure>

另外,Jetty 自帶的示例:webapps.demo/test.xml 中也有security realm相關的配置。 
解決了這兩個問題後,Jenkins示例URL:http://192.168.52.11:8080/jenkins/ 就能夠正常訪問了。session

參考資料:app

http://www.eclipse.org/jetty/documentation/current/what-jetty-version.htmleclipse

http://stackoverflow.com/questions/9111759/http-error-503-accessing-jenkins-reason-service-unavailablewebapp

https://wiki.jenkins-ci.org/display/JENKINS/Jetty

相關文章
相關標籤/搜索