gpt4 book ai didi

java - 如何解决 - ERROR StatusLogger No Log4j 2 配置文件找到

转载 作者:行者123 更新时间:2023-12-02 02:33:05 28 4
gpt4 key购买 nike

使用 Intellij 在 IDE 中运行时出现以下错误 -

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

当我运行 jar 文件时 -

trevor@trevor-Lenovo-YOGA-510-14AST:~/decent/Master5/out/artifacts/Master5_main_jar$ java -jar Master5.main.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at BlockgetConnection.(BlockgetConnection.java:12) at BlockgetAccount.getAccountByName(BlockgetAccount.java:31) at BlockgetStart.main(BlockgetStart.java:8) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 3 more

我没有明确记录,我假设在体面的逻辑中需要以某种方式记录。我包含了我的 build.gradle。我已经包含了一些日志记录的依赖项。对解决方案有什么想法吗?

代码(主类)-

import ch.decent.sdk.model.Account;

public class BlockgetStart {


public static void main(String[] args) {
BlockgetAccount anAccount = new BlockgetAccount();
Account myAcct = anAccount.getAccountByName("trevor3");
}

}

使用此类的实例 -

import ch.decent.sdk.DCoreApi;
import ch.decent.sdk.crypto.Address;
import ch.decent.sdk.crypto.Credentials;
import ch.decent.sdk.model.Account;
import ch.decent.sdk.model.AssetAmount;
import ch.decent.sdk.model.Fee;
import ch.decent.sdk.model.TransactionConfirmation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

@Component
public class BlockgetAccount {
// connection to accounts
private static final Long AMOUNT_OF_DCT_REQUIRED_FOR_CREATION = 100000L;

@Autowired
private BlockgetConnection connectionExample;
@Autowired
private BlockgetLogin loginExample;
@Autowired
private BlockgetGenerateKeys generateKeys;

/**
* Example of getting any account by its name.
*
* @param accountName name of the account e.g. dw-account
* @return Account instance for given account name
*/
public Account getAccountByName(String accountName) {

connectionExample = new BlockgetConnection();
final DCoreApi dcoreApi = connectionExample.connect();

return dcoreApi
.getAccountApi()
.getByName(accountName)
.blockingGet();
}

/**
* Example of account creation with initial fee.
*
* @param newAccountName Unique account name that you wish to create.
* @return Confirmation about transaction
*/
public TransactionConfirmation createAccount(String newAccountName) {

final DCoreApi dcoreApi = connectionExample.connect();
final Credentials credentials = loginExample.login();
final Address newAccountPublicKey = generateKeys.generateKeys();
final AssetAmount dctAssetAmount = new AssetAmount(AMOUNT_OF_DCT_REQUIRED_FOR_CREATION);
final Fee initialFee = new Fee(dctAssetAmount.getAssetId(), AMOUNT_OF_DCT_REQUIRED_FOR_CREATION);

return dcoreApi.getAccountApi().create(
credentials,
newAccountName,
newAccountPublicKey,
initialFee
).blockingGet();
}
}

构建.gradle-

plugins {
id 'java'
}

group 'com.blockget.Master5'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

jar { manifest { attributes 'Main-Class': 'BlockgetStart' } }

allprojects {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}

dependencies {
// https://mvnrepository.com/artifact/org.springframework/spring-context
// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.8.RELEASE'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-ap
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.12.0'

testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.github.DECENTfoundation:DCoreKt-SDK:2.3.1'

}

我得到这个是为了 jar 故障 -

    trevor@trevor-Lenovo-YOGA-510     14AST:~/decent/Master5/out/artifacts/Master5_main_jar$ jar tf     Master5.main.jar     META-INF/MANIFEST.MF    META-INF/    BlockgetNftMgr.class    BlockgetLogin.class    BlockgetConnection.class    BlockgetNft.class    BlockgetStart.class    BlockgetAccount.class    BlockgetGenerateKeys.class

记录器应该在这里吗?

最佳答案

如果将“资源”目录标记为“资源根”会有帮助吗?

在这种情况下,您需要将 log4j2.xml 文件放在 src 文件夹下,以便能够在类路径上找到它。将其放在 src/main/resourcessrc/test/resources 下。

其他解决方案:使用系统属性-Dlog4j.configurationFile=file:/path/to/file/log4j2.xml

关于java - 如何解决 - ERROR StatusLogger No Log4j 2 配置文件找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57219449/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com