使用java -jar jenkins.war --httpPort=XXXX启动Jenkins报错【解决方案】
👉欢迎关注博主【米码收割机】
👉一起学习C++、Python主流编程语言。
👉机器人、人工智能等相关领域开发技术。
👉主流开发、测试技能。
一. 启动Jenkins报错
错误1:错误描述
在cmd中,执行启动命令行:
java -jar jenkins.war --httpPort=8080
报错信息如下:
Main verifyJavaVersion
严重: Running with Java class version 63 which is not in the list of supported versions: [52, 55, 61]. Run with the --enable-future-java flag to enable such behavior. See https://jenkins.io/redirect/java-support/
java.lang.UnsupportedClassVersionError: 63.0
at Main.verifyJavaVersion(Main.java:147)
at Main.main(Main.java:108)
Jenkins requires Java versions [17, 8, 11] but you are running with Java 19 from D:\JDK-19
java.lang.UnsupportedClassVersionError: 63.0
at Main.verifyJavaVersion(Main.java:147)
at Main.main(Main.java:108)
错误1: 解决方案
根据提供的错误信息,您正在使用 Java 19,而 Jenkins 支持的 Java 版本为 8、11 和 17。为了解决此问题,您需要安装一个受支持的 Java 版本并将其设置为默认的 Java 版本。
1)安装JDK
下载并安装适合您操作系统的支持的 Java 版本(例如 JDK 8、11 或 17)。您可以从 Oracle 官方网站 或 AdoptOpenJDK下载。
2)查看java版本
下载完成后,打开一个新的命令提示符窗口,运行以下命令以验证 Java 版本:
java -version
确保显示的版本与您安装的 JDK 版本相匹配。
3)重新启动 Jenkins
使用以下命令启动 Jenkins
java -jar jenkins.war --httpPort=8080
错误2:错误描述
在cmd中,执行启动命令行:
java -jar jenkins.war --httpPort=8080
报错信息如下:
Running from: D:\Jenkins\Jenkins.war
webroot: $user.home/.jenkins
2023-05-06 09:08:57.518+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @301ms to org.eclipse.jetty.util.log.JavaUtilLog
2023-05-06 09:08:57.572+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2023-05-06 09:08:57.586+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2023-05-06 09:08:57.644+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.45.v20220203; built: 2022-02-03T09:14:34.105Z; git: 4a0c91c0be53805e3fcffdcdcc9587d5301863db; jvm 17.0.7+7
2023-05-06 09:08:57.925+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2023-05-06 09:08:57.955+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2023-05-06 09:08:57.956+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2023-05-06 09:08:57.957+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2023-05-06 09:08:58.287+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: C:\Users\mech-mind_lcl.jenkins found at: $user.home/.jenkins
2023-05-06 09:08:58.365+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@32057e6{Jenkins v2.346.2,/,file:///C:/Users/mech-mind_lcl/.jenkins/war/,AVAILABLE}{C:\Users\mech-mind_lcl.jenkins\war}
2023-05-06 09:08:58.374+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStop: Stopped ServerConnector@282003e1{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2023-05-06 09:08:58.375+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#stopScavenging: node0 Stopped scavenging
2023-05-06 09:08:58.378+0000 [id=1] INFO hudson.WebAppMain#contextDestroyed: Shutting down a Jenkins instance that was still starting up
java.lang.Throwable: reason
at hudson.WebAppMain.contextDestroyed(WebAppMain.java:383)
at org.eclipse.jetty.server.handler.ContextHandler.callContextDestroyed(ContextHandler.java:1080)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextDestroyed(ServletContextHandler.java:584)
at org.eclipse.jetty.server.handler.ContextHandler.contextDestroyed(ContextHandler.java:1043)
at org.eclipse.jetty.servlet.ServletHandler.doStop(ServletHandler.java:319)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:94)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:180)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:201)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:108)
at org.eclipse.jetty.security.SecurityHandler.doStop(SecurityHandler.java:430)
at org.eclipse.jetty.security.ConstraintSecurityHandler.doStop(ConstraintSecurityHandler.java:423)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:94)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:180)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:201)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:108)
at org.eclipse.jetty.server.session.SessionHandler.doStop(SessionHandler.java:520)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:94)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:180)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:201)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:108)
at org.eclipse.jetty.server.handler.ContextHandler.stopContext(ContextHandler.java:1066)
at org.eclipse.jetty.servlet.ServletContextHandler.stopContext(ServletContextHandler.java:386)
at org.eclipse.jetty.webapp.WebAppContext.stopWebapp(WebAppContext.java:1454)
at org.eclipse.jetty.webapp.WebAppContext.stopContext(WebAppContext.java:1420)
at org.eclipse.jetty.server.handler.ContextHandler.doStop(ContextHandler.java:1120)
at org.eclipse.jetty.servlet.ServletContextHandler.doStop(ServletContextHandler.java:297)
at org.eclipse.jetty.webapp.WebAppContext.doStop(WebAppContext.java:547)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:94)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:180)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:201)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:108)
at org.eclipse.jetty.server.Server.doStop(Server.java:470)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:94)
at winstone.Launcher.shutdown(Launcher.java:354)
at winstone.Launcher.(Launcher.java:217)
at winstone.Launcher.main(Launcher.java:405)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at Main._main(Main.java:342)
at Main.main(Main.java:117)
2023-05-06 09:08:58.383+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStop: Stopped w.@32057e6{Jenkins v2.346.2,/,null,STOPPED}{C:\Users\mech-mind_lcl.jenkins\war}
Exception in thread “Jenkins initialization thread” java.lang.NoClassDefFoundError: hudson/util/HudsonFailedToLoad
at hudson.WebAppMain$3.run(WebAppMain.java:261)
Caused by: java.lang.ClassNotFoundException: hudson.util.HudsonFailedToLoad
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:538)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
… 1 more
2023-05-06 09:08:58.386+0000 [id=1] INFO winstone.Logger#logInternal: Jetty shutdown successfully
java.io.IOException: Failed to start Jetty
at winstone.Launcher.(Launcher.java:206)
at winstone.Launcher.main(Launcher.java:405)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at Main._main(Main.java:342)
at Main.main(Main.java:117)
Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.server.Server.doStart(Server.java:401)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at winstone.Launcher.(Launcher.java:202)
… 7 more
Caused by: java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
… 14 more
2023-05-06 09:08:58.391+0000 [id=1] SEVERE winstone.Logger#logInternal: Container startup failed
java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
Caused: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.server.Server.doStart(Server.java:401)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at winstone.Launcher.(Launcher.java:202)
Caused: java.io.IOException: Failed to start Jetty
at winstone.Launcher.(Launcher.java:206)
at winstone.Launcher.main(Launcher.java:405)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at Main._main(Main.java:342)
at Main.main(Main.java:117)
错误2: 解决方案(方法1)
从日志中可以看出,Jenkins启动失败的原因是端口冲突。错误信息显示:“Address already in use: bind”,表明8080端口已被其他程序占用。因此,Jenkins无法在8080端口上启动。
1)切换端口启动
在cmd中,使用8081或其他端口启动:
java -jar jenkins.war --httpPort=8082
2)浏览器查看
打开浏览器输入http://localhost:8082
。可以看到Jenkins已经启动。
错误2: 解决方案(方法2)
1)关闭被占用的端口
查找并关闭占用8080端口的程序:使用以下命令查找占用8080端口的程序:
Windows:
netstat -ano | findstr :8080
Linux:
sudo lsof -i :8080
找到占用端口的程序后,结束相关进程,然后重新启动Jenkins。
2)浏览器查看
打开浏览器输入http://localhost:8080
。可以看到Jenkins已经启动。