代码之家  ›  专栏  ›  技术社区  ›  vico

在jamvm上运行log4j

  •  0
  • vico  · 技术社区  · 2 年前

    尝试在jamvm虚拟机上使用log4j运行简单的java应用程序:

    jamvm -cp ".:log4j-api-2.11.2.jar:log4j-core-2.11.2.jar" m.main
    

    出现错误:

    Exception in thread "main" java.lang.NoClassDefFoundError: java/util/Objects
       at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:90)
       at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:59)
       at java.lang.reflect.VMConstructor.construct(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:319)
       at java.lang.Class.newInstance(Class.java:1154)
       at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
       at m.main.<clinit>(main.java:7)
    Caused by: java.lang.ClassNotFoundException: java.util.Objects not found in java.lang.ClassLoader$1{urls=[file:/opt/rfidSrv/./,file:/opt/rfidSrv/log4j-api-2.11.2.jar,file:/opt/rfidSrv/log4j-core-2.11.2.jar], parent=null}
       at java.net.URLClassLoader.findClass(URLClassLoader.java:531)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:341)
       at java.lang.ClassLoader$1.loadClass(ClassLoader.java:1112)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:293)
       at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:90)
       ...6 more
    

    那里出了什么问题,如何解决?

    Oracle Java上的相同命令运行良好:

    java -cp ".:log4j-api-2.11.2.jar:log4j-core-2.11.2.jar" m.main
    

    密码

    m包;

    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    public class main {
        private static final Logger LOG =  LogManager.getLogger(main.class);
         
        public static void main(String[] args) 
            {
            LOG.info("---startting---");
            
            LOG.debug("This Will Be Printed On Debug");
            LOG.info("This Will Be Printed On Info");
            LOG.warn("This Will Be Printed On Warn");
            LOG.error("This Will Be Printed On Error");
            LOG.fatal("This Will Be Printed On Fatal");
     
            LOG.info("Appending string: {}.", "Hello, World");
            
            }
    }
    
    0 回复  |  直到 2 年前