代码编译时JDK版本和运行时JDK版本不一致启动项目报错

时间:2023-03-08 17:55:45

java编译:

java编译就是.java文件变成.class文件的过程,这个过程一般在我们常用的编译器中进行,例如Ecliplse和IDEA等:下面以IDEA举例:

代码编译时JDK版本和运行时JDK版本不一致启动项目报错

执行上述编译使用的JDK版本就是我们不同编译器所设置的java版本:

代码编译时JDK版本和运行时JDK版本不一致启动项目报错

java运行:

java运行就是我们编译得到的字节码文件(就是.class文件)在安装了Java运行环境(JVM)的计算机上运行,此时使用的的JDK版本就是我们配置的JAVA_HOME对应的java版本。我们可以通过在命令行执行:java -version来查看当前计算机上的java版本

代码编译时JDK版本和运行时JDK版本不一致启动项目报错

编译时JDK版本和运行时JDK版本不一致:

如果上述两种JDK版本不一致,很容易在运行项目时产生报错,就像我就遇到了下面的报错:我的解决办法就是将两者JDK版本调节为同一个版本就OK了

五月 ,  :: 上午 org.apache.tomcat.util.modeler.BaseModelMBean invoke
严重: Exception invoking method createStandardContext
javax.management.RuntimeOperationsException: Exception invoking method manageApp
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.access$(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
[-- ::,] Artifact test1:war exploded: Error during artifact deployment. See server log for details.
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$(TCPTransport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
at java.lang.Thread.run(Thread.java:)
Caused by: org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool:
at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:)
at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:)
at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:)
at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
... more 五月 , :: 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory manager

补充:

在一个计算机上编译得到的字节码文件(就是.class文件),可以复制到任何一个安装了Java运行环境的计算机上直接运行。然后字节码文件由虚拟机负责解释执行,即Java虚拟机将字节码翻译成本地计算机的机器码,然后将机器码交给本地的操作系统运行。

由于在一个计算机上编译得到的字节码文件可以复制到任何一个安装了Java运行环境的计算机上直接使用,所以字节码其实是一种“中间代码”,这也就是为什么“Java语言能够一次编译,处处运行,也就是Java跨平台的原因。”所以称Java是一种“半编译,半解释的语言”,即源程序——>编译——>字节码——>字节码解释程序——>对应平台的机器语言。