Exception in thread "main" java.lang.Noclassdeffounderror: org/apache/logging/lo g4j/Logmanager

Asked

Viewed 587 times

-1

I am trying to start a jar file and as soon as I run, I get this error! You can help me?

C:\Unky\Web\BloodStrikeServer-master>mvn clean package -Dmaven.test.skip=true
'mvn' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

C:\Unky\Web\BloodStrikeServer-master>java -jar target/lobbyplayer-0.0.1-SNAPSHOT
-fat.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/lo
g4j/LogManager
        at com.bloodstrike.lobbyserver.Main.<clinit>(Main.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager

        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

C:\Unky\Web\BloodStrikeServer-master>pause Pressione qualquer tecla para continuar. . .

Main archive:

package com.bloodstrike.lobbyserver;


import java.io.FileOutputStream;

import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import com.bloodstrike.lobbyserver.manager.NetworkManager;

import io.vertx.core.Vertx;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetSocket;

public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) throws Throwable {
        logger.info("===============================================================================");
        logger.info("BloodStrike Lobby Server");
        logger.info("Créditos: ExtremsX");
        logger.info("Versão: 0.1 Beta");
        logger.info("===============================================================================");

        logger.info("Carregando Configurações");
        Config.loadConfig();

        logger.info("Iniciando NetworkManager");
        NetworkManager.getInstance();

            Vertx.vertx().setTimer(1000, id -> {
                    try {
                        startClientDebug();
                        logger.info("Iniciando DUMPER");
                    } catch (Exception e) {
                        logger.error("Falha ao iniciar o DUMPER");
                    }
            });


        logger.info("Iniciando NetworkServer");
        NetworkServer.getInstance();
    }

    private static void startClientDebug() throws Exception {
        Logger log = LoggerFactory.getLogger(Main.class);
        int port = Integer.parseInt("4000");
        String host = "0.0.0.0";
        FileOutputStream fos = new FileOutputStream("./network.dump");

        NetServer server = Vertx.vertx().createNetServer();
        server.connectHandler(handler -> {
            NetClient client = Vertx.vertx().createNetClient();
            log.error("Nova conexão recebida de " + handler.remoteAddress());

            client.connect(port, host, res -> {
                if (!res.succeeded()) {
                    log.error("Erro ao se conectar ao servidor", res.cause());
                    try { fos.close(); } catch (Exception e) { }
                    return;
                }
                log.error("Erro ao se conectar ao servidor", res.cause());

                NetSocket socket = res.result();
                // Do cliente para o servidor
                handler.handler(buffer -> {
                    try { 
                        fos.write("\n\nClient -> Servidor\n".getBytes()); 
                        fos.write(buffer.getBytes());
                    } catch (Exception e) { }
                    socket.write(buffer);
                });

                // Do servidor para o cliente
                socket.handler(buffer -> {
                    try { 
                        fos.write("\n\nServidor -> Client\n".getBytes());
                        fos.write(buffer.getBytes());
                    } catch (Exception e) { }
                    handler.write(buffer);
                });
            });
        });
        server.listen(3999, res -> {
            if (!res.succeeded())
                return;
            log.info("Servidor DUMPER iniciado na porta 3999");
        });
    }
}
  • If in your file main, you put a // before any call, use or import of Logger, it works?

  • Have you tried switching calls to log4j for System.out.println?

1 answer

0

C:\Unky\Web\BloodStrikeServer-master>mvn clean package -Dmaven.test.skip=true
'mvn' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

Maven is not properly installed. Simply inspect the Maven and make sure that the folder bin is in the variable %PATH%.

As for this command:

java -jar target/lobbyplayer-0.0.1-SNAPSHOT-fat.jar

Failed to put log4j in the classpath. It should be like this:

java -cp log4j.jar -jar target/lobbyplayer-0.0.1-SNAPSHOT-fat.jar

Maybe you also need to put several other Jars, would be like this:

java -cp pasta1/jar1.jar;pasta2/jar2.jar -jar target/lobbyplayer-0.0.1-SNAPSHOT-fat.jar

Utilize ; to separate the name of one JAR from the other in the classpath. You may end up needing a lot of Jars.

  • I’ve done it and it’s still the same

  • I don’t know what else to do, I tried so many things and it never worked, I was always in the same mistake, only now I went to appeal for help from someone

  • @Júliosousa The log4j JAR is in which folder?

  • java -cp classpaths/log4j-api-2.6.2.jar;classpaths/log4j-core-2.6.2.jar -jar target/lobbyplayer-0.0.1- SNAPSHOT-fat.jar pause after changing, I created the folder and set the jars]

  • And those two Jars are in the briefcase C:\Unky\Web\BloodStrikeServer-master\classpaths, right? It’s classpaths in the same plural?

  • First of all, besides using the necessary ones for the app, you need another log4j api?

  • If that was the problem, he’d probably make a different mistake.

  • Yes. I purposely put it in the plural, but I put the paste in the plural and the cp as well

  • Well, then I don’t know what it is. It must be something silly, but I don’t know.

  • I have tried everything, change log4j to slf4j, I have tried to change something in manifest.mf, but it always stays in the same error. I can’t understand why this :P

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.