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


    java编译:

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

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

    java运行:

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

     

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

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

    五月 22, 2019 7:05:35 上午 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:305)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:598)
        at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:547)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
        at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
        at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
        at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
        at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [2019-05-22 07:05:35,048] Artifact test1:war exploded: Error during artifact deployment. See server log for details.
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
        at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131)
        at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1909)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1798)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1757)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1743)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1247)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:874)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:317)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5031)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
        at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1390)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
        ... 35 more
    
    五月 22, 2019 7:05:44 上午 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory manager

     补充:

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

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

  • 相关阅读:
    面试笔记之手写单例模式
    Java学习笔记六:Java最基础
    Mac下终端工具iTerm2的快捷键
    Typescript引用类型--字符串
    Typescript引用类型--数组
    Typescript函数作用域
    Typescript的函数定义方式
    初识Typescript以及Typescript的安装
    VS Code前端开发常用插件和常用快捷键
    Vue CLI3项目构建
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/10903660.html
Copyright © 2020-2023  润新知